Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
master_t
Partner - Creator II
Partner - Creator II

Getting active selections using the SDK: problem with locked fields

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:

master_t_0-1670323137279.png

 

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:

master_t_1-1670323761195.png

What am I missing?

Labels (2)
1 Solution

Accepted Solutions
alex_colombo
Employee
Employee

Hi @master_t when you create the ListObjectDef object try to set ShowAlternatives property to true. In this way you should receive all values. Here our doc and here an example but with Capability APIs.

View solution in original post

3 Replies
alex_colombo
Employee
Employee

Hi @master_t when you create the ListObjectDef object try to set ShowAlternatives property to true. In this way you should receive all values. Here our doc and here an example but with Capability APIs.

Øystein_Kolsrud
Employee
Employee

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
}

 

master_t
Partner - Creator II
Partner - Creator II
Author

Thanks @alex_colombo  and @Øystein_Kolsrud , your solution worked perfectly.