Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
Francis_Kabinoff
Former Employee
Former Employee

Here are some useful topics related to alternate states and the Capability APIs

Creating Alternate States

Creating an alternate state with the Capability APIs is easy. Just do the following

app.addAlternateState('StateName');

Alternate states created through the Capability APIs can be saved in the app or created every session. If you try to add an alternate state that already exists though, you may get some unexpected behavior. That's why I would recommend using something like the following when adding an alternate state:

app.getAppLayout(function(layout) {

     if(layout.qStateNames.indexOf('StateName') === -1) {

          app.addAlternateState('StateName');

     }

});

This will check to make sure the alternate state doesn't already exist before adding it to the app.

Alternate States and Session Objects

For session objects, such as lists and hypercubes, it's super easy to assign them to an alternate state. All you need to do is include the 'qStateName' parameter in your object definition. Below is an example of a list object that fetches 10 rows from the field 'SomeField', and is assigned to the state 'StateName'.

app.createList({

    'qDef': {

        'qFieldDefs': ['SomeField'],

    },

    'qInitialDataFetch': [

        {

            'qHeight': 10

        }

    ],

    'qStateName': 'StateName'

}, function(reply){});

Alternate States and Qlik Sense Objects

You can't assign a Qlik Sense object directly to an alternate state, but with a bit of set analysis, you can make an object respond to selections on an alternate state. Let's take, for example, a measure that is simply the sum of some field name, and add the set analysis needed to make it respond to selections on an alternate state.

Sum( {$< FieldName = P( {StateName} FieldName ) >} FieldName)

Making Selections on Alternate States

Making selections on alternate states is as simple as passing an extra parameter to the Field API methods. Example below

app.field('FieldName', 'StateName').select([0], false, false);

The above example would select the first row in the "FieldName" field, on state "StateName". The important part of the above is the second parameter to the app.field() method. Utilizing that second paramter, you can apply just about any method in the Field API to an alternate state.