Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi everyone
I'm trying to use the .NET SDK to get all the active selections in a Qlik Sense app.
At the moment I'm using this code:
public void GetCurrentSelections()
{
IApp app = GetApp();
using (var currentSelection = app.GetCurrentSelection())
{
foreach (var item in currentSelection)
{
Listbox listBoxObj = app.CreateGenericSessionObject(new ListboxProperties()
{
ListObjectDef = new ListboxListObjectDef()
{
Def = new ListboxListObjectDimensionDef { FieldDefs = new string[] { item.Field } },
InitialDataFetch = new NxPage[] { new NxPage { Height = 10000, Left = 0, Top = 0, Width = 1 } },
AutoSortByState = new NxAutoSortByStateDef() { DisplayNumberOfRows = 1 },
},
Info = new NxInfo() { Type = "listbox" },
}) as Listbox;
foreach (var dataPage in listBoxObj.Layout.ListObject.DataPages)
{
foreach (NxCellRows rows in dataPage.Matrix)
{
foreach (var cell in rows)
{
Console.WriteLine($"Value {cell.Text} is {cell.State}");
}
}
}
app.DestroyGenericSessionObject(listBoxObj.Id);
}
}
}
Basically, I get the list of fields with active selections and for each one I find the locked/selected/etc. states of each value by building a session object ListBox and fetching the items.
However, there's something wrong going on: I'm having problems with detecting values that are LOCKED but EXCLUDED. Instead of having the StateEnumType.EXCL_LOCKED state, values that are both locked and excluded simply have the StateEnumType.EXCLUDED state.
For example, in a situation like this:
the above function prints:
Value Non-Sponsored Trial is LOCKED
Value Sponsored Trial is EXCLUDED
Value Compassionate Use is EXCLUDED
etc.
Is this a bug? Or am I doing this wrong?
Note that in the NxCurrentSelectionItem object (the "item" in the outer most for-each in my function) the state count sseems to be correctly reported, as you can see here:
What am I missing?
Like @alex_colombo writes, that "ShowAlternatives" setting is probably what you want. Try defining your ListObjectDef like this:
ListObjectDef = new ListboxListObjectDef()
{
Def = new ListboxListObjectDimensionDef { FieldDefs = new string[] { item.Field } },
InitialDataFetch = new NxPage[] { new NxPage { Height = 10000, Left = 0, Top = 0, Width = 1 } },
AutoSortByState = new NxAutoSortByStateDef() { DisplayNumberOfRows = 1 },
ShowAlternatives = true
}
Thanks @alex_colombo and @Øystein_Kolsrud , your solution worked perfectly.