Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Announcements
Qlik® Product Spotlight: Discover what’s possible. Get more from our products.
See for yourself. Register today.
billgates
Contributor

[Qlick Sense 3.0] I don't understand code execution order. Please Assist.

Hello!

I'm beginner in qlik and I'm trying work with Qlick Sense 3.0 programmatically

I'm working with application described here

https://community.qlik.com/message/1114490#1114490

I have not enough experience with javascript and I need help with next code:

define( [

  'qlik'

],

function (qlik) {

  'use strict';

   function run(){

  

   console.log("START");

  

  var app = qlik.currApp();

  app.field('Year').selectValues([1997, 1998, 1999, 2000], true, true);

  var selections = [];

     app.getList("SelectionObject", function(reply){

        console.log("APP.GETLIST");

        $.each(reply.qSelectionObject.qSelections, function(key, value) {

             console.log("$.EACH");

             selections.push({'field':value.qField, 'selected':value.qSelected});

         });

     });

  

  console.log("END");

  return selections;

  }

  return {

  paint: function ($element) {

  var result = run();

  console.log(result);

  return qlik.Promise.resolve();

  }

  };

} );

 

Order of execution is: START --> END --> APP.GETLIST --> $.EACH

h_1472745099_2754125_a3da9817b7.png

That is not right for me. And i do not understand why code execution has this order.

I want to code execution will has next order: START  --> APP.GETLIST --> $.EACH --> END

What should I do for this?

I will appreciate for links, where I can read about it.

Thanks.

Tags (1)
1 Solution

Accepted Solutions
billgates
Contributor

Re: [Qlick Sense 3.0] I don't understand code execution order. Please Assist.

Possible Solution:

var app; // Global app

var appSelections;

define( [

  'qlik'

],

function (qlik) {

  'use strict';

  function run(promise){

  console.log("START");

  app = qlik.currApp();

  app.field('Year').selectValues([1997, 1998, 1999, 2000], true, true);

  var loc_selections = [];

     app.getList("SelectionObject", function(reply){

        console.log("APP.GETLIST");

        $.each(reply.qSelectionObject.qSelections, function(key, value) {

             console.log("$.EACH");

             loc_selections.push({'field':value.qField, 'selected':value.qSelected});

         });

     console.log("END");

     promise.resolve(loc_selections);

     });

 

 

  console.log("RESULTS:");

  appSelections = loc_selections;

 

  console.log(appSelections);

 

  }

  return {

     paint: function ($element) {

       var result = run(qlik.Promise);

     }

   };

  }

);

1 Reply
billgates
Contributor

Re: [Qlick Sense 3.0] I don't understand code execution order. Please Assist.

Possible Solution:

var app; // Global app

var appSelections;

define( [

  'qlik'

],

function (qlik) {

  'use strict';

  function run(promise){

  console.log("START");

  app = qlik.currApp();

  app.field('Year').selectValues([1997, 1998, 1999, 2000], true, true);

  var loc_selections = [];

     app.getList("SelectionObject", function(reply){

        console.log("APP.GETLIST");

        $.each(reply.qSelectionObject.qSelections, function(key, value) {

             console.log("$.EACH");

             loc_selections.push({'field':value.qField, 'selected':value.qSelected});

         });

     console.log("END");

     promise.resolve(loc_selections);

     });

 

 

  console.log("RESULTS:");

  appSelections = loc_selections;

 

  console.log(appSelections);

 

  }

  return {

     paint: function ($element) {

       var result = run(qlik.Promise);

     }

   };

  }

);

Community Browser