10 Replies Latest reply: Jul 20, 2018 4:11 PM by Anjali Keswani RSS

    GetLayout method not returning selections

    Anjali Keswani

      Hello,

      I am using Angular4, and trying to get selections on QS app.

      This is how I am calling createsessionobject first:

      return new Promise((resolve, reject) => {
              var createSessionSelectionMsg = {           
                 "jsonrpc": "2.0",            
                 "id": 2,
                 "method": "CreateSessionObject",
                 "handle": parseInt(handle),
                 "params": [
                    {
                   "qInfo": {
                   "qId": "",
                   "qType": "SessionLists"                   
                    },     
                     "qSelectionObjectDef": {}
                    }
                  ]
      } .........

      after that I am calling GetLayout

      return new Promise((resolve, reject) => {

         var glayout = {

         "jsonrpc": "2.0",

        "id": 2,

        "method": "GetLayout",

        "handle": 2 ,//parseInt(handle),

         "params": []

       

       

      }

      ...

      The above two returns this result--

      result:
      qReturn:
         qGenericId: "13f471d2-ee35-480d-a965-a98d783abbc2"
         qGenericType: "SessionLists"
         qHandle: 2
         qType: "GenericObject"

       

      result:

      qLayout:

      qInfo: {qId: "13f471d2-ee35-480d-a965-a98d783abbc2", qType: "SessionLists"}

      qSelectionInfo:{ }

      qSelectionObject: {qBackCount: 0, qForwardCount: 0, qSelections: Array(0)}

       

      I am selecting a field value on the app, but the qSelections is not returning anything, don't know why.

      am I calling the above correctly?

      Can anyone please help me ?

      Thanks!

       

       

        • Re: GetLayout method not returning selections
          Erik Wetterberg

          Hi,

          are you using enigmajs? Or capabilities API? Or building something yourself?

           

          Erik Wetterberg

            • Re: GetLayout method not returning selections
              Anjali Keswani

              Thanks Erik,

               

              I am just building a web app with angular front end, displaying our Qliksense apps list and when click on a app, it opens up the app.

               

              I am able to get the selections list, how can I send a link to a user so if he opens up the link ,he should see the same selections on the same app on the hub? trying to use GetField and SelectValues but not sure, it's not working yet.

              • Re: GetLayout method not returning selections
                Anjali Keswani

                Actually the GetField and SelectValues are working now, sorry I am new to Qlik, so taking some time to get it work.

                How can I send this as a link ? so if user opens it up ,he should see the same app + Sheet + selections ???

                Thanks in advance.

                • Re: GetLayout method not returning selections
                  Anjali Keswani

                  So I am able to create a link, so if the user clicks that, then I would call Engine API to display the fields with those selection values. (The user would see the link when he in the same app. )

                  this is not working yet.

                  I am calling GetField and SelectValues, then after going through documentation, I think I need to call GetLayout also.

                  I am passing in the field handle (returned by getfield) in GetLayout (what is this id here I don't know..):

                  var getlayout = {

                     "jsonrpc": "2.0",

                     "id": 2,

                     "method": "GetLayout",

                     "handle": parseInt(handle),

                     "params": []

                  }

                  ...

                   

                   

                   

                    resolve(data.result.qLayout.qSelectionObject.qSelections);

                   

                  ....

                  Getting an error :

                  error:

                  code: -32601

                  message: "Method not found"

                  parameter: "GetLayout"

                   

                  although the same method is used in getting selections (CreateSessionObject + GetLayout) and is working there. is there a problem with field handle ? or is it something else ?

                  Please help.

                  Thanks.

                   

                   

                    • Re: GetLayout method not returning selections
                      Erik Wetterberg

                      Hi,

                      The id field is just an id for the message, need to be unique, just using a sequential number is good.

                       

                      The message ’method not found’ means you are trying to call GetLayout on an object Thatcher does not have usch a method. Probably the handle valurnorna is wrong.

                       

                      Erik Wetterberg

                        • Re: GetLayout method not returning selections
                          Anjali Keswani

                          Does it mean that the "field" handle cannot be passed to GetLayout ? if so, how would I get the selections displayed then?

                           

                            this.getField(qlikWs, element.qField, appHandle).then(reply => {

                            console.log('select field', fieldHandle) // this returns 2

                             this.selectValues(qlikWs, fieldHandle, element.qSelected).then(reply => { // this returns true in qReturn

                              this.getLayout(fieldHandle, qlikWs).then(sel => { // this throws error

                           

                           

                          Thanks Erik.

                          • Re: GetLayout method not returning selections
                            Anjali Keswani

                            I was watching a video on QS Engine API explorer, it's a good way to test APIs.

                            So ,I tested to apply selections with Getfield and SelectValues, then I called the Macros->List Selections, it showed me the CreateSessionObject and GetLayout to be called. When I hit execute, the GetLayout does not return qSelections.

                            I think I need to pass in the selections  in CreateSessionObject, so GetLayout knows and can pick it up.

                            This is what it shows me:

                            "method": "CreateSessionObject",

                            "handle": 1,

                            "params": [

                              {

                               "qInfo": {

                                "qType": "CurrentSelection"

                               },

                               "qSelectionObjectDef": {}

                              }

                            ],

                            ...

                            How can I pass current selections in this ? I tried something like this below in qSelectionObjectDef, but this doesn't return selections in GetLayout:

                            "qSelectionObjectDef": {

                                 "qSelections": [{

                                  "qField":"Weekday",

                                  "qSelected":"Tue"

                                 }

                                 ]

                                }

                             

                            I think this is not correct as qSelectionObjectDef is for passing in Definitions/structures of objects and not values, is that right ? if I can pass the selections in CreateSessionObject, then it will probably work.

                            How can I pass selections above ? I also tried

                            "qSelectionObject: {

                                 "qSelections": [{

                                  "qField":"Weekday",

                                  "qSelected":"Tue"

                                 }

                                 ]

                                },

                            qSelectionObjectDef:{}

                             

                            but nothing works as of now. :-(

                            • Re: GetLayout method not returning selections
                              Anjali Keswani

                              So it is working for me. The problem that I was passing the selected values in SelectValues method has qIsNumeric set to false, and I kept testing with the field "Weekday" that ,to my surprise, is set to numeric type. Once I set that to true, it worked and showed me the selection on the app.

                                "qText": val ,

                                 "qIsNumeric": true 

                               

                              I ran "List Fields" macro on engine api explorer and got this info:

                              {

                                    "qName": "Weekday",

                                    "qCardinal": 7,

                                    "qTags": [

                                     "$numeric",

                                     "$integer"

                                    ],

                                    "qSrcTables": [

                                     "datetime"

                                    ]

                                   },

                               

                              Now, to know the selected fields are numeric or not, is there an easy way to get that info? so I can pass that to SelectValues.

                               

                               

                              • Re: GetLayout method not returning selections
                                Anjali Keswani

                                So Erik, it's working to some extent. Can you help me with SelectValues method. it works for non-numeric field types. But for , say Weekday field which is numeric, I need to pass in the following info :

                                "qText": "Thu",

                                    "qIsNumeric": true,

                                    "qNumber": 0

                                I am calling GetFieldDescription method to get the "qIsNumeric" value and passing it to SelectValues method above.

                                Now, I need to know the "qNumber" value also. The method takes 0 as default, and is showing "Sun" as selected value, although it should be "Thu" (for which the qNumber should be 4) . How do I know the qNumber of text that I am passing in ? can I call a method that returns me this info?

                                • Re: GetLayout method not returning selections
                                  Anjali Keswani

                                  marking it as correct answer ,as that was the initial problem.

                                  For anyone interested in knowing the solution of further problems I was having with GetField and SelectValues not working for numeric fields, I came to know that the way Qlik works is that it creates list object on those fields behind the scenes. So ,instead of calling GetField and SelectValues, I am now calling CreateObject (the field is created as ListObject), and then GetListObjectData (to get all the values of that field), and then matching the selected values in that list returned and passing on to SelectListObjectValues to get it selected. At the end, just CreateSessionObject and GetLayout methods to display the selections. That made my selections applied on the screen when user clicks the link (which has selections passed in it).