Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
sheldonqlik
Contributor II
Contributor II

Qliksense custom measure property for extension with expression value

I have created a custom property for a measure in my extension

CustomMeasureProp:{

          type:"string",

          label:"Custom Measure Property",

          ref:"customMeasureProperty",

          expression: "optional"

}

In the QlikSense Desktop I am able to add my extension and see the custom property when adding my measure.

I populate it with my EXPRESSION Max(value).

THE QUESTION.  

How do I access that evaluated expression through the api?

I have used my code

$scope.backendApi.getProperties().then(function(reply){

          angular.forEach(reply.qHyperCubeDef.qMeasures,function(measure){

           console.log('MEASURE',measure);

           if(typeof measure.customMeasureProperty!=='undefined'){

              console.log('MEASURE LABEL', measure.customMeasureProperty);

         }

});

Rather than returning the evaluated expression when looking  at the object measure.customMeasureProperty, it returns the string Max(value).

So how do get the evaluated value?

1 Solution

Accepted Solutions
Alexander_Thor
Employee
Employee

It is very possible, you are just not reading what I'm posting for you.
Stop accessing the properties through getProperties(). Period.

Why? Because you are accessing the definition of the hypercube, not the hypercube itself

Here are two working examples, 1 for Attribute Expressions and 1 for Measure properties

definition.PNG

attributeexpression.pngmeasureproperty.png

View solution in original post

27 Replies
Alexander_Thor
Employee
Employee

Most likely you just need to add a = sign before Max(value) otherwise it's interpreted as a string.

You could also change the type to number if you want to ensure you get a number back and not a string.

There is no need to fetch the properties btw, the customMeasureProperty should be available on the layout object or on scope if you aren't referencing your custom property as a measure on the HyperCubeDef which is not inluded in the snippet.

sheldonqlik
Contributor II
Contributor II
Author

I am actually doing it as a custom property of a measure. 

I added the '=' sign but realized that it automatically does that anyway. 

I have used this code.

$scope.backendApi.getProperties().then(function(reply){

          angular.forEach(reply.qHyperCubeDef.qMeasures,function(measure){

           console.log('MEASURE',measure);

           if(typeof measure.customMeasureProperty!=='undefined'){

              console.log('MEASURE LABEL', measure.customMeasureProperty);

         }

});


Unfortunately it comes back as a

  1. qStringExpression: Object
    1. qExpr: "=Max(value)";

In the object.  So I am still stuck there.  Don't know if I can get the evaluated expression.



Alexander_Thor
Employee
Employee

Can you share the full definition? Also what happens when you changed the type to number instead of string?

A working example can be found here, line 95-102 WaterfallChart/waterfall.js at master · mindspank/WaterfallChart · GitHub

A string expression wont be evaluated if ifs surrounded by single quotes so the properties panel probably interprets your input as a string since you have the type set to that.

Alexander_Thor
Employee
Employee

Also set the expression property to "always" and it will never evaluate your expression as a string regardless of type.

You can check the documentation for that over here, https://help.qlik.com/sense/2.0/en-us/developer/Subsystems/Extensions/Content/Howtos/custom-string-p...

Alexander_Thor
Employee
Employee

It could also be the case that since you are accessing the properties of the hypercube and the not the hypercube itself that the expression has not been evaluated yet.

The evaluated hypercube will be accessible from the layout, $scope.layout.qHyperCube

sheldonqlik
Contributor II
Contributor II
Author

You may be very right.  I don't think what I am attempting to do may be possible.  But here is my definition

define([], function () {

        var settings = {

            uses: "settings",

            items: {

            measures : {

                uses : "measures",

                min : 1,

                max : 10,

                items:{

                         //allows for custom labels using functions in the measure. Can use an expression to set it.

                        InformationLabelProp:{

                            type:"string",

                            label:"Custom Label",

                            ref:"props.tInformationLabel",

                            expression: "always",

                            defaultValue: ""

                        }

}

                }

        }

    };

     // Return values

    return {

        type: "items",

        component: "accordion",

        items: {

            settings: settings

        }

    };

});

Then in my angular controller I am doing the get from the backendApi like i stated in the original

$scope.backendApi.getProperties().then(function(reply){

  angular.forEach(reply.qHyperCubeDef.qMeasures,function(measure){

          console.log('MEASURE',measure);

    }

  console.log('MATRIX',layout.qHyperCube.qDataPages[0].qMatrix[0]);

  });

Thanks so much for the information yesterday.  I just don't know where in the hypercube that data would be.

Alexander_Thor
Employee
Employee

It is very possible, you are just not reading what I'm posting for you.
Stop accessing the properties through getProperties(). Period.

Why? Because you are accessing the definition of the hypercube, not the hypercube itself

Here are two working examples, 1 for Attribute Expressions and 1 for Measure properties

definition.PNG

attributeexpression.pngmeasureproperty.png

sheldonqlik
Contributor II
Contributor II
Author

thank you much! I was not listening apparently! thanks much. 

yblake
Partner - Creator II
Partner - Creator II

Hi Alexander,

I tried to use exactly your both properties definitions (Sense Desktop 2.1.1 build 22).

But when I enter a formula in measures properties I get a Json rpc error :

jsonrpcerror.PNG

The property formula is not saved.


Layout hypercube data matrix object log in the console shows qAttrExps.qValue.0.qNum equal to "Nan" for calculated measure property.


Layout hypercube measure info shows newLabel with 'TE'.


When I edit again the object, both formulas has vanished.

Should I set up some special initial properties to get this working ?

Any other ideas ?

Regards