Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
kevindevos
Partner - Contributor II
Partner - Contributor II

Capability API and Field API call promise timing issue

Hi all,

I am having issues with some api calls in my dev-hub extension. 
I need to run multiple api calls in sequence to our qlik sense server, but it seems that the returned promises are resolving too early. 

I have wrote a small script to reproduce this issue. The core of this script is the following:
(Assume sleep(x) sleeps for x milliseconds, and app, fieldName, and value are defined properly)

 

for (var i = 0; i < 25; ++i) {
  // clear
  await app.clearAll();

  // select
  await app.field(fieldName).toggleSelect(value, false);

  // print selections
  await app.getList("SelectionObject", async function (reply) {
      console.log(reply.qSelectionObject.qSelections.length);
      await app.destroySessionObject(reply.qInfo.qId);
    });

    await sleep(200);

}

await sleep(1000);
await app.clearAll();

 

This script runs 25 loop iterations, where on each iteration it first clears all selections, then selects a value, then prints the number of values selected on each iteration all in sequence. 

I made sure that only a single value is indeed selected in the app with toggleSelect, and when running the script i have made sure there are no current selections active.

Script result:

kevindevos_0-1659439703209.png

Every so often i get a result of 0 selections, and occasionally an error (either object not found or request aborted). It should always be 1 after each iteration. Does someone have an idea for solving this issue? 

Labels (2)
1 Solution

Accepted Solutions
kevindevos
Partner - Contributor II
Partner - Contributor II
Author

To add some closure to this issue, this was a bug with the qlik selections api and it has been resolved in one of the most recent qlik updates.

View solution in original post

4 Replies
edwin
Master II
Master II

i would use combination of promise arrays and chained promises.  this is a great reference for it:

JavaScript Promises: an introduction (web.dev)

esp the part about chaining

kevindevos
Partner - Contributor II
Partner - Contributor II
Author

Hi, thank you for the link, it looks like a really good resource. I will bookmark it!

I implemented a variation of the script but using promise chaining, and im getting the same result.
And i tried adjusting the sleep delay between requests, the lower it is, the worse the results are.

I really suspect that this is an issue with qlik, as the request promises are simply resolving too early while Qlik is probably still processing something for a very short duration after the resolve. It's the only explanation i can think of for this. I don't think i made any mistakes with the above script using async/await, but if did i apologise in advance.

I need it to wait properly to prevent requests from arriving and processing out of order and causing an inconsistent app state.  Adding timeouts also isn't the solution. (A request could potentially take (timeout+1) seconds to finish so there is no guarantee)


kevindevos
Partner - Contributor II
Partner - Contributor II
Author

To add some closure to this issue, this was a bug with the qlik selections api and it has been resolved in one of the most recent qlik updates.

Dcarvalho
Contributor II
Contributor II

@kevindevos , at my work we are having this same problem. Do you know if has any update that solves this problem to Qliksense version of november, 2019 - Patch 4 - 13.51.8 ?

How do I download this patch to solve it on this version of Qliksense?