Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
loki20beta
Partner - Contributor
Partner - Contributor

How to format a number in extension according to Qlik Formatting Pattern?

Hello,

I'm just starting with my extensions development studies and have probably a dumb question: how to format a number I'm calculating inside my extension JavaScript code according to qlik formatting pattern?

Here is a very basic thing I need to do. A user of extension inputs a number in properties panel, I'm doing some calculations in the extension code and then I need to show the result, something like this: 

 

paint: function ( $element, layout ) {
var myNewValue;
myNewValue = 100 + layout.myValue;
var html = "" + myNewValue + ""
$element.html( html );
return qlik.Promise.resolve();
}

 

 

But when I'm creating this html element I want to ask Qlik to format this "myNewValue" with Num()  function. Basically I need the string result of Num( myNewValue, '#,##0.##', '.' , ',' ) 

Am I missing something obvious? I understand that I can get strings from hypercube but how to do the same with my own calculated values?

Labels (2)
1 Reply
oops
Contributor
Contributor

It looks like this is what you are looking for.

In short, there is enigmajs model, which you can access from your extension via:

this.backendApi.model.enigmaModel

 This model allows you to make calls to QIX Engine API. So in your case you would do:

this.backendApi.model.enigmaModel.app.evaluate(`Num(${myNewValue}, '#,##0.##', '.' , ',' )`)
.then((evalResult) => {
  //do what you need with the evalResult
});

Hope this helps.