Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi!
We are developing a Qlik Sense extension where we need to get a list of all currently selected values (we internally maintain a structure that contains field names and an array of selected values for each field). The problem is that we haven't found a way to get a list of ALL selected values (including those values which are currently excluded - but they still have the tick next to the value in the filter box). Here's what we've tried so far:
1.) The chart function GetFieldSelections() does indeed return all selected values (including the not-green ones). However, if the selection is based on a formula, the function returns that formula rather than an array of values, so we cannot use this function to get the values.
2.) field.getData() > this function returns the "S" state for the green values and the "X" state for all excluded values (even if those excluded values are selected and have the tick), so we cannot distinguish between excluded and excluded-but-selected values.
3.) createList and retrieve data pages from a list > the same as 2.) applies, we cannot distinguish between excluded and excluded-but-selected values.
Essentially my question is: what is a bullet-proof method to fetch all selected values from a field (including values which are currently excluded)?
Thanks and BR,
Bernd
Hi @Bernd_Podhradsky I usually used list object for getting all values of a field or all selected values (including excluded but selected).
You can do it with both Capability APIs and Engine APIs.
For Capability APIs, as you mentioned, you can use createList method. Below an example. The property which enables you to show all states is "qShowAlternatives": true. Default is false and with this, you will see always X for excluded selected.
app.createList({
"qDef": {
"qFieldDefs": [
"Dim1"
]
},
"qShowAlternatives": true,
"qInitialDataFetch": [{
qTop : 0,
qLeft : 0,
qHeight : 3,
qWidth : 1
}]
}, function(reply) {
$.each(reply.qListObject.qDataPages[0].qMatrix, function(key, value) {
console.log('state: ', value[0].qState);
});
;
});
For Engine APIs you have to create a session object and then get list object data.
Create session object starting from doc object (Qlik Sense app name in Engine API). Remember to add "qShowAlternatives": true.
{
"handle": 1,
"method": "CreateSessionObject",
"params": {
"qProp": {
"qInfo": {
"qType": "ListObject"
},
"qListObjectDef": {
"qStateName": "",
"qLibraryId": "",
"qDef": {
"qFieldDefs": [
"Dim1"
],
"qSortCriterias": [
{
"qSortByLoadOrder": 1
}
]
},
"qShowAlternatives": true
}
}
},
"outKey": -1,
"id": 24
}
From the response received use GetListObjectData method for getting values
{
"handle": 11,
"method": "GetListObjectData",
"params": {
"qPath": "/qListObjectDef",
"qPages": [
{
"qLeft": 0,
"qTop": 0,
"qWidth": 1,
"qHeight": 3
}
]
},
"outKey": -1,
"id": 25
}
Response with data. In my example value C is excluded but selected.
{
"jsonrpc": "2.0",
"id": 25,
"delta": true,
"result": {
"qDataPages": [
{
"qMatrix": [
[
{
"qText": "B",
"qNum": "NaN",
"qElemNumber": 0,
"qState": "S"
}
],
[
{
"qText": "C",
"qNum": "NaN",
"qElemNumber": 1,
"qState": "XS"
}
],
[
{
"qText": "A",
"qNum": "NaN",
"qElemNumber": 2,
"qState": "S"
}
]
],
"qTails": [],
"qArea": {
"qLeft": 0,
"qTop": 0,
"qWidth": 1,
"qHeight": 3
}
}
]
}
}
Hope this helps
Hi @Bernd_Podhradsky I usually used list object for getting all values of a field or all selected values (including excluded but selected).
You can do it with both Capability APIs and Engine APIs.
For Capability APIs, as you mentioned, you can use createList method. Below an example. The property which enables you to show all states is "qShowAlternatives": true. Default is false and with this, you will see always X for excluded selected.
app.createList({
"qDef": {
"qFieldDefs": [
"Dim1"
]
},
"qShowAlternatives": true,
"qInitialDataFetch": [{
qTop : 0,
qLeft : 0,
qHeight : 3,
qWidth : 1
}]
}, function(reply) {
$.each(reply.qListObject.qDataPages[0].qMatrix, function(key, value) {
console.log('state: ', value[0].qState);
});
;
});
For Engine APIs you have to create a session object and then get list object data.
Create session object starting from doc object (Qlik Sense app name in Engine API). Remember to add "qShowAlternatives": true.
{
"handle": 1,
"method": "CreateSessionObject",
"params": {
"qProp": {
"qInfo": {
"qType": "ListObject"
},
"qListObjectDef": {
"qStateName": "",
"qLibraryId": "",
"qDef": {
"qFieldDefs": [
"Dim1"
],
"qSortCriterias": [
{
"qSortByLoadOrder": 1
}
]
},
"qShowAlternatives": true
}
}
},
"outKey": -1,
"id": 24
}
From the response received use GetListObjectData method for getting values
{
"handle": 11,
"method": "GetListObjectData",
"params": {
"qPath": "/qListObjectDef",
"qPages": [
{
"qLeft": 0,
"qTop": 0,
"qWidth": 1,
"qHeight": 3
}
]
},
"outKey": -1,
"id": 25
}
Response with data. In my example value C is excluded but selected.
{
"jsonrpc": "2.0",
"id": 25,
"delta": true,
"result": {
"qDataPages": [
{
"qMatrix": [
[
{
"qText": "B",
"qNum": "NaN",
"qElemNumber": 0,
"qState": "S"
}
],
[
{
"qText": "C",
"qNum": "NaN",
"qElemNumber": 1,
"qState": "XS"
}
],
[
{
"qText": "A",
"qNum": "NaN",
"qElemNumber": 2,
"qState": "S"
}
]
],
"qTails": [],
"qArea": {
"qLeft": 0,
"qTop": 0,
"qWidth": 1,
"qHeight": 3
}
}
]
}
}
Hope this helps