13 Replies Latest reply: May 19, 2017 6:51 AM by Florian Salfenmoser RSS

    How to add dimensions and expressions for an extension object?

    OLEKSANDR NERUSH

      Is it possible to add dimensions and/or expressions for an extension object using JavaScript?

        • Re: How to add dimensions and expressions for an extension object?
          OLEKSANDR NERUSH

          After couple of hours googling community and digging into the QlikView Ajax library i've found solution and would like to share ideas here.

           

          So, to add dimension and/or expression from Extension's JavaScript code you can write following code:

           

          Qva.AddExtension('MyExtension', function(){

           

               // extension's code is ommited

           

              // to add dimension:

              this.Layout.SetProperty("Chart.Dimension.Add", "", false)

              this.Layout.SetProperty("Chart.Dimension.0.Field", "MyDimensionField", true);

           

             // to add expression

            this.Layout.SetProperty("Chart.Expression.Add", "", false)

             this.Layout.SetProperty("Chart.Expression.0.0.Definition", "SUM(MyValueField)", true)

          });

           

           

          But there is a new question: how to determine the number of dimensions and expressions?

            • Re: How to add dimensions and expressions for an extension object?

              Hi Alex,

               

              do you found a solution of your problem?

              I've tried to use your code, it works very well.

               

              Have you tried to remove a dimension or expression?

               

              Have a nice day,

              Mattia

              • Re: How to add dimensions and expressions for an extension object?
                Tushar Suvarna

                Hi ,


                Was googling and just came across your post

                 

                Basically i am trying to do some dynamic selection from an extension object for applying selection i need to use
                _this.Data.SelectTextsInColumn(0, true, "*");

                 

                here the _this.Data object refrences the Dimension field so basically i tried you above to dynamically change the field in the javascript here is the code

                function getData()

                            {

                                var lineDelimiter = '\n';

                                var tagDelimiter = ':';

                                var valueDelimiter = ';';

                 

                  var currentSelectionQv =_this.Layout.Text0.text;

                   //  alert('Value from Expression ' + currentSelectionQv);

                 

                                var arrSelectionLines = currentSelectionQv.split(lineDelimiter);

                           

                                if (arrSelectionLines.length > 0 && arrSelectionLines[0] != '-') {

                                    for (i = 0; i < arrSelectionLines.length; i++) {

                                        var line = arrSelectionLines[i];

                                        var tagPos = line.indexOf(tagDelimiter);

                                        var fieldName = line.substr(0, tagPos);

                                     

                                        var fieldValues = line.substr(tagPos + 1, line.length - tagPos).split(valueDelimiter);

                                   

                  alert(fieldName); // Selected Field Name

                                        // to add dimension:

                      _this.Layout.SetProperty("Chart.Dimension.Add", "", false)

                  _this.Layout.SetProperty("Chart.Dimension.0.Field", fieldName, true);

                  alert('Layout Ran !');

                 

                  alert(fieldValues); //Select Field Value

                                 

                                    }

                 

                                }

                                else

                                {

                                    //Do Nothing

                                }

                 

                            }

                 

                 

                 

                 

                I will be basically using arrSelectionLines  variable to feed in my Input string containing the Field name and Field value from a Web Service . Now the above code is running in a circular loop any idea why ?

                • Re: How to add dimensions and expressions for an extension object?
                  Stevan Grubić

                  Hello, Mattia,

                   

                  I know it's been a long time, but only now have I stumbled upon this, searching for the answer to your question:

                  "how to determine the number of dimensions and expressions?"

                   

                  With a bit of googling I've found this answer: QlikView Extension determine amount of Dimensions from first data row (if multiple) · GitHub, to quote:

                   

                  // get amount of Dimensions

                  var nDimensions = this.Data.Rows[0].filter(function(col){return !(col.color == undefined);}).length;

                   

                  Apparently, dimensions columns in QV generated data get their own color each, while expressions columns' color is undefined. Definitely a weird way to get to the information as useful and simple as this... but hey.

                   

                  Hope someone except for me will find this useful. Thank you, ralfbecher of GitHub.