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!
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
Here’s an example: https://dl.dropboxusercontent.com/u/17417247/QlikView/Wordpress/AutoReload%20Desktop%20Client.qvw
Thx Lucian. I thought that a QV app will be automatically reloaded after 10 minutes as you wrote. This does not happen automatically.
It works here. I’m using version 11.2 SR2
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?
I modified the file so it does an initial reload when first opened. Please download the example and try again.
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
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?
When you use the QlikView server, just set the reload schedule of the document in management console.
I know that 🙂 I was thinking about a situation when a QV app is scheduled to refresh once a day but here and then a user needs to refresh it immediately to capture today’s data, etc.
It is not a good idea to let your users trigger the reloads, but there are some legitimate situations. Please note that EDX API is changing with every major version.
Your situation can be addressed using EDX calls: http://community.qlikview.com/docs/DOC-2650
neno! what did you do to made this right?
Very useful!
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
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
Hi Lucian,
is possible hide the script execution window
Thanks you very much.
Use
ActiveDocument.ReloadEx 0,1
instead of
ActiveDocument.Reload
Thanks you very much.!!!!
works perfect!!
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.
You can get faster answers on community.qlik.com
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?
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
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
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
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
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
same issue as of carlos !
create another variable like vCtrl and set default value to 0
put in vTriggerReload >> if((now()-ReloadTime())*1440 >= 10, vCtrl + 1)
Hi luciancotea,
i have created the file and it is reloading when we open the document that time only. But i want one change when the document is in closed state also it will reload
This is my requirement can you suggest me where should i modify??