Auto reload every 10 minutes – desktop client

There are situations when you want your document to be permanently opened and auto reload without the help of QlikView server.

To do that we need the auto reload macro and a trigger. The macro looks like that:

Sub ReloadDoc
   ActiveDocument.Reload
   ActiveDocument.Save
End sub

As trigger we will use a variable that checks the difference between current time and last reload time. We will add an action on Onchange event of that variable, action that will run our macro.

So, add a vTriggerReload variable with the following expression:

=if((Now()-ReloadTime())*1440 >= 10, vTriggerReload+1, 0)

Go to Settings -> Document properties -> Triggers tab:

    • In “Variable event trigger” box, select vTriggerReload variable and press the “OnChange” -> “Add action(s)” button.
    • In the “Actions” window that popped up press the “Add” button, select “External” action type, “Run macro” action and press “OK”.
    • Write “ReloadDoc” in “Macro name” box and press “OK” buttons all the way.

You may have to run the first reload, since QlikView doesn’t recalculate anything until a user action is recorded.

In the end, we have to force QlikView to do the initial reload because it doesn’t calculate anything if no change is recorded. So, in the same “Triggers” tab from document settings, we add a “Run macro” external action on “OnOpen” document event.

Tip: seems that variables are not always recalculated if there’s no object to use them. A hidden textbox which calls the “TriggerReload” variable can help in forcing QlikView to do the refresh.

Happy Qliking!

Advertisements
Tagged with: , , ,
Posted in Macro, Script
27 comments on “Auto reload every 10 minutes – desktop client
  1. Neno says:

    Hi Lucian,

    I found this useful and tried to enable it in one QV11 app but with no change. I believe I’ve done something wrong or skipped a step. Can you please look into the steps I did?

    Thanks,
    Neno

  2. Neno says:

    I use 11.0 SR2 Could this be the reason?
    Just to be sure I understand this correctly: I expect the app to be open and then in certain number of minutes it will be automatically (with no user intervention) reloaded and saved?

    • luciancotea says:

      I modified the file so it does an initial reload when first opened. Please download the example and try again.

      • Aman says:

        Hi Lucian, Even I am facing the same issue. I am using qlik 11 and using the same settings whic you told above, but it is not automatically reloading. I have made the settings to reload when the doc is opened for the first time. Still the automatic reload is not working. Please suggest

  3. Neno says:

    Thx Lucian. Now it works. Is there a possibility for this to work when an app is opened in server (App@) or from the Access Point?

  4. Robert Hall says:

    Very useful!

  5. Sumita says:

    Hi Lucian,

    Could you please tell me how to pass a variable value to QlikView reload script when I am reloading the file through macro?

    Script
    Load *
    from abc
    where Product= $(vPRODUCT )

    Macro
    sub shtReload
    set varCurrentQvw = ActiveDocument
    vPRODUCT = ActiveDocument.Variables(“vProduct”).GetContent.String
    varCurrentQvw.Reload
    varCurrentQvw.Save
    end sub

    Thanks,
    Sumita

    • luciancotea says:

      You have to store the new value into the variable, save the document and reload.

      SUB setVariable(varName, varValue)
      set v = ActiveDocument.Variables(varName)
      v.SetContent varValue, true
      END SUB

      sub shtReload
      set varCurrentQvw = ActiveDocument
      setVariable “vPRODUCT” , “NewValue”
      varCurrentQvw.Save
      varCurrentQvw.Reload
      varCurrentQvw.Save
      end sub

  6. Gerardo says:

    Hi Lucian,

    is possible hide the script execution window

    Thanks you very much.

  7. Gerardo says:

    Thanks you very much.!!!!
    works perfect!!

  8. Gerardo says:

    Hi Lucian,
    you can help me again?
    how can execute a store procedure from oracle, conected by OLE DB ?

    you can help me with this please.

  9. Hugo Sousa says:

    Hello,
    I’m trying to implement your tip, but when I click on the Add action (s) button, nothing happens, I am using the version 11.20.12664.0 SR9 Edition (x64). anyone have any idea about this issue?

  10. joydipp1988 says:

    Hi Lucian,
    Very helpful blog post. I’m done with the example you posted. But I have some doubts. Here in the example reload is happening after 1 minute as ReloadMinutes variable is set to 1. But I’m interested in variable time gap i.e. sometimes I want to load after 5 sec, sometimes after 10 sec or sometimes 15 sec etc. So how to do that ? And please explain why you multiplied the difference by 1440 ? Why 1440, I mean how you choose that particular no? Is there any rule to choose the number ? Thanks in advance.

    Regards,
    Joy

    • luciancotea says:

      There are 1440 minutes in a day: 24*60. The used functions return datetime values where the time is the fractional part. Therefore, 1 minute is 1/1440

  11. joydipp1988 says:

    Hi Lucian,
    Thanks for your early reply. Things are clear now. I applied your logic and I’m multiplying the difference by 86400 (24 * 60 * 60). But without manual intervention it is not reloading. Every time I have to press the “Reload Now” button. Can you please guide me what is happening ? You can get the app from the below link-
    https://drive.google.com/open?id=0B2CHBSZUT0VJYnZjSjNJSElFMzQ
    Thanks in advance.

    Regards,
    Joy

  12. Dick says:

    Thanks for this clear explanation! I have one addition. When I implemented this according to your example nothing would happen.

    This was because initially the variable vTriggerReload has no value, so vTriggerReload+1 will also result in an unknown value and not trigger the OnChange event.

    The solution to make this work is initialize the variable to 0 (zero) in the load script

  13. Carlos says:

    Hi my friend, the script was very useful but i have a problem, when is trigered after ten minutes, then it starts to reload every 2 o 3 seconds withoud ending, so i’m confused why it’s not working.

    If somethings come to your mind i will very thankful

    Thank you
    Regards

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: