Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

riccardozenere
Contributor III

JScript: WaitForIdle or equivalent

Hi everyone,

I'm looking for a way to make the WaitForIdle (or equivalent function, even a custom one) work on a JScript macro.

What I'm trying to achieve is to pause the application (not make it "sleep", as I've already done with custom code) in order to select a value on a field and give time to the application to "update the layout" with the selection before taking a screenshot.

Currently with the lone sleep the screenshot is taken before I can see the layout update.

Do you have any hint about how to do this in JScript?

Tags (2)
1 Solution

Accepted Solutions
riccardozenere
Contributor III

Re: JScript: WaitForIdle or equivalent

Sorry for the very late answer, I had literally no time

Anyway, this is what I discovered:

  • Upgrading to QlikView 11.20 SR13 the actions are executed in the right order (so they truely wait till the end of the previous action). Anyway this solved my problem only partially, because from batch the macro wasn't working properly once again. Calling the right way the WaitForIdle (see below) solved my problem
    Side note: at the time I wrote the question I was trying the macro with QlikView 11.20 SR7 and SR12.
  • The right way to call the WaitForIdle is this: Application.WaitForIdle(). My mistake was trying to call it using the ActiveDocument...


Thanks to everyone for the help!

12 Replies
sinanozdemir
Valued Contributor III

Re: JScript: WaitForIdle or equivalent

It has been a while I didn't code in JScript, but I think you can use if you haven't already tried it:

setTimeout(function() {alert("take your screenshot");}, 1000);

sinanozdemir
Valued Contributor III

Re: JScript: WaitForIdle or equivalent

You can also look into using WinJS libraries:

https://msdn.microsoft.com/en-us/library/windows/apps/br229706.aspx

riccardozenere
Contributor III

Re: JScript: WaitForIdle or equivalent

Hi Sinan, thanks for your reply

I've already tried that (only difference is the Application.Msgbox instead of the alert) but it's not working... When I use it opens the Edit Module and does nothing at all!

riccardozenere
Contributor III

Re: JScript: WaitForIdle or equivalent

I'm not sure about how to use them, using directly

WinJS.Application.stop();

won't work...

Do I need to import anything? If not, could you make a working example, please?

thanks

sinanozdemir
Valued Contributor III

Re: JScript: WaitForIdle or equivalent

I believe you need to download WinJS from this link WinJS: Windows Library for JavaScript - Windows app development

Apart from this, the only way is to use setTimeout() as far as I know.

riccardozenere
Contributor III

Re: JScript: WaitForIdle or equivalent

Tried that, but including it in the module gave me many errors: on the WinJS base/ui file there are many strings that ends with a ",", which I'm not sure about... Of course the parser gives me error, and I think they are wrong too... but I hope they left them there for a purpose

Still no luck with setTimeout, but thanks for trying

Let's see if anybody else has an idea/workaround for my problem

MVP
MVP

Re: JScript: WaitForIdle or equivalent

Here is how you can use InputBox and MsgBox from JScript:

// JScript

function Test()

{    

     personName = qvlib.InputBox("What is you name?")

     msg = "Hello " + personName + " !"

     qvlib.MsgBox(msg)

}

MVP
MVP

Re: JScript: WaitForIdle or equivalent

Try this:

function Test()

{

  qvlib.MsgBox('Started.');

  app = ActiveDocument.GetApplication();

  qvlib.MsgBox( '[' + app.OSName() + ']' );

  app.WaitForIdle();

  qvlib.MsgBox('Ended.');

}

riccardozenere
Contributor III

Re: JScript: WaitForIdle or equivalent

Hi Petter, thanks for your reply,

I've tried it and it works, but I don't think this example is the best one... When you use a MsgBox or something else where you need the user to execute an action (in this situation click the "ok" button to proceed with the execution of the macro) you stop the execution, so it's not like having it scheduled...

Anyway I found the solution to my problem, I'll post it later

Community Browser