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

Measure creation via javascript

Hello,

The case that I'm trying, is to create a measure on the fly and then get the value and add it to my html.

I'm trying to create a measure via javascript, using qsocks.

I used Engine api explorer to create the json message.

{

  "handle": 1,

  "method": "CreateMeasure",

  "params": {

  "qProp": {

  "qInfo": {

  "qId": "SumQuantityId",

  "qType": "Measure"

  },

  "qMeasure": {

  "qLabel": "SumQuantity",

  "qDef": "=sum(Quantity)",

  "qGrouping": 0,

  "qExpressions": [

  ""

  ],

  "qActiveExpression": 0

  },

  "qMetaDef": {}

  }

  },

  "id": 6,

  "jsonrpc": "2.0"

  }

This seems to work fine using the explorer.

When i use qsocks, I get "error: {"code":9,"parameter":"Missing Type","message":"Empty parameters"}".

.....

qapp.createMeasure(obj).then(function(reply) { 

  console.log("reply: " + JSON.stringify(reply)); 

}, function(error) {  

  console.log("error: " + JSON.stringify(error));

});

.....

Of course, I'm connected to my app, and the "obj" is the json message provided above.

Can someone help me?

Thanks in advance,

Eleni

3 Replies
Øystein_Kolsrud
Employee
Employee

If you just want to evaluate the expression, then you might want to look into this engine API method: Evaluate method ‒ Qlik Sense

I'm not sure if that method is available in through the API you are using though.

ErikWetterberg

If you don't really want to create a measure, but only get the expression evaluated, you could use the Capability APIs and the createGenericObject method. For your expression that would be something like this:

app.createGenericObject( {

     sumQuantity: { qValueExpression: "=sum(Quantity)" }

}, function ( reply ) {

//handle the reply

//the value will be in reply.sumQuantity

//and this function will be called whenever the value changes

});

Erik

eleni_theodorid
Partner - Creator
Partner - Creator
Author

Thanks a lot both of you for your quick replies.

app.evaluate("=sum(Quantity)").then(function ( reply ) {

     // do something

}, function(error) {

     // do something

});

This works fine, but it sums all "quantity", instead of selected.