Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi to everyone,
I'm looking for a javascript sample to read the possible values of a specific field using qlik sense 3.1 java script.
I have try to use the field getData method but this return all data, not only the possibile data according to the current selections.
This is the sample code I have tested :
var app = qlik.currApp(this);
var fieldData = app.field("CustomerName").getData(20, "V");
for (t=0; t<fieldData.rows.length; t++)
{
console.log("Value = [ " + fieldData.rows
}
I'm looking for a java script code with the same functionality as the following VBS code I have used with QlikView :
Set fullList = ActiveDocument.Fields("CustomerName").GetPossibleValues
For t = 0 to fullList.Count - 1
Call MsgBox("Value = " & fullList.item(t).Text)
Next
Anyone could help me please?
Many Thanks
Max
Hey Max,
There are two constructs within QIX that you can use.
Either the ListObject which reads the state vectors of a field and returns the full data set, i.e selected, optional and excluded values.
Or you can use a HyperCube construct which is part of calculation layer which only returns Selected and Optional values. In the Capabilities API you can use the createCube method to create a HyperCube that would contain a dimension which lists the field you want to fetch values for.
Some pseudo code:
app.createCube({
qDimensions: [{
qDef: { qFieldDefs: ['Dim1'] }
}],
qInitialDataFetch: [{ qTop: 0, qLeft: 0, qWidth: 1, qHeight: 10000 }]
})
.then(function(model) {
model.Validated.bind(function() {
// HyperCube has been updated
console.log(model.layout)
})
console.log(model.qHyperCube.qDataPages)
})
Or as a interactive fiddle: Getting a single field - JSFiddle
Hi Alexander,
many thanks for you answer. Do you have a code example also for the first construct?
1# construct - "Either the ListObject which reads the state vectors of a field and returns the full data set, i.e selected, optional and excluded values."
Actually when you call getData on the field interface a ListObject is created in the background for you but you could use the createList method, the full ListObject definition can be found here: http://help.qlik.com/en-US/sense-developer/3.1/Subsystems/EngineAPI/Content/GenericObject/PropertyLe...
Some code:
app.createList({
qListObjectDef: {
qDef: { qFieldDefs: ['SomeField'] }
},
qInitialDataFetch: [{ qTop: 0, qLeft: 0, qWidth: 0, qHeight: 10000 }]
})
.then(function(model) { console.log(model) })