Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[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.

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

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);

     }

   };

  }

);

View solution in original post

1 Reply
Anonymous
Not applicable
Author

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);

     }

   };

  }

);