Qlik Community

Qlik Sense Integration, Extensions, & APIs

Discussion board where members can learn more about Integration, Extensions and API’s for Qlik Sense.

Announcements
Qlik® Product Spotlight: Discover what’s possible. Get more from our products.
See for yourself. Register today.
Not applicable

Qlik Sense API read possible values of a specific field?

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.qText + " ]");

}

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

3 Replies
akl
Not applicable

Re: Qlik Sense API read possible values of a specific field?

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

Not applicable

Re: Qlik Sense API read possible values of a specific field?

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."

akl
Not applicable

Re: Qlik Sense API read possible values of a specific field?

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) })