3 Replies Latest reply: Nov 4, 2014 9:38 AM by Erik Wetterberg RSS

    Qlik Sense Mashup API code.

    Serhan Celebi

      Hello,

       

      Trying to arrange a Qlik Sense mashup code that will select a series of locations based on a specific range around user's location (for example: 1000 km around of my location etc).

       

      I am able to get the location and calculate the distance to/ from each coordinate with a function. I need to get the resultset of the coordinate points that are matching my condition, and in the next step I need to select these values.

       

      I'm a little bit confused about how to use the Qlik Sense API though. Do I need to use getList or createList methods and how? Seems like I cannot assign the resulting values to a specific array. For example the code below from API ref; I'm not able to make it work.

       

      Probably I'm missing something really basic.

       

      $('#getLocation').click( function()

                                  {

       

        app.getList('Location', function(reply)

                     {

                       var str = "";

                       $.each(reply.qFieldList.qItems, function(key, value)

                              {

                                str += value.qName + ' ';

                            

                              });

                       alert(str);

                     });

                                  

             });

       

      Edit 1 : Seems like I can't even make any app.field method work (like SelectAll). Any ideas?

       

      BR

       

      Serhan

        • Re: Qlik Sense Mashup API code.
          Erik Wetterberg

          Hi Serhan,

          the getList() method is for listing Qlik Sense internal objects, like fields etc. getList('Location') will not work.

           

          For listing the contents of a field try the createList() method.

           

          Erik

            • Re: Qlik Sense Mashup API code.
              Serhan Celebi

              Hello Erik,

               

              So do you mean getList is only used for getting the whole list of field with no restriction? Because my field's name is Location in the above example. I still could not understand the difference between the two methods. Thanks to lazy API reference .

               

              Also I have another problem with API. In the code below, I want to make a simple selection. But seems like the ready-made variable "app" is out of scope or something. I'm not able to make anything work with it.

               

              /*global require, alert*/

              /*

              *

              * @owner Enter you name here (xxx)

              */

              /*

              *    Fill in host and port for QlikView engine

              */

              var config = {

                  host: window.location.hostname,

                  prefix: "/",

                  port: window.location.port,

                  isSecure: window.location.protocol === "https:"

              };

              require.config( {

                  baseUrl: ( config.isSecure ? "https://" : "http://" ) + config.host + (config.port ? ":" + config.port: "") + config.prefix + "resources"

              } );

               

              require( ["js/qlik"], function ( qlik ) {

                  qlik.setOnError( function ( error ) {

                      alert( error.message );

                  } );

               

               

                  //open app and get objects

                  var app = qlik.openApp("Executive Dashboard.qvf", config);

                  $(".qvobject").each(function() {

                      var qvid = $(this).data("qvid");

                      app.getObject(this, qvid);

                  });

               

              } );

               

              /* Document Ready */

              $(document).ready(function() {

               

                app.field('Product').selectPossible();

               

                  $("#toggle").click(function() {

                   

                     $("#CurrentSelections").toggle("fast");

                   

                  });

               

                       $("#toggle").hover( function()

                                                   {

                                                     $(this).addClass("highlight");

                                                   },

                                                   function()

                                                   {

                                                     $(this).removeClass("highlight");

                                                   }

                                                  );

              });

               

              Serhan

                • Re: Qlik Sense Mashup API code.
                  Erik Wetterberg

                  Hi

                  You find the documentation for getList() here. You can use getList() to get a list of all fields in the app. In your case I guess 'Location' would be one of the entries.

                   

                  Of you want the actual content of the 'Location' field you use createList() method. Reference is here.

                   

                  And yes, you are right app is out of scope in your code snippet.You need to call it within the function where it is defined, preferably after the openApp() call.

                   

                  Erik