OnApplyBookmark document event trigger
QlikView offers different document event triggers: OnAnySelect, OnOpen, OnPostReduceData and OnPostReloadData. They all enable you to respond to certain events generated by QlikView. This can be useful in many cases. For instance, I often use the OnOpen trigger to have the current date selected when the user opens the document.
The other day I was developing a QlikView app where I wanted to execute a macro action when the users applied a bookmark. In this case I needed to refresh a chart with different measures that were selected by the user. QlikView does not have an OnApplyBookmark trigger. So how do we persuade QlikView to help us achieve this goal?
Open the document properties (CTRL-ALT-D) and go to the tab Variables. Select the just created OnApplyBookmark variable and check the Include in Bookmarks checkbox (see red rectangle 1 in the image below). This ensures that whenever the user creates a bookmark the value of our variable is included in this bookmark.
Select the Triggers tab in the document properties and add an OnInput action to the OnApplyBookmark variable. (In this situation the OnChange does not work in the IE plugin so therefore it is best to use the OnInput.) Blue rectangle 2 in the image below illustrates how to add an OnInput action to the variable.
From here on out you can select any action to be executed when a bookmark is applied. For this example I will execute a macro function. Therefore click on the add button to add an action and select External – Run Macro. Type OnApplyBookmarkFired in the Macro Name field (see image below).
Sub OnApplyBookmarkFired
MsgBox(“A bookmark was applied”)
End Sub
Now confirm all the dialogs with OK and start testing. If all is well you should get a messagebox each time you apply a bookmark that was created after implementing this change.
Why does this work? We have setup our newly introduced variable OnApplyBookmark in such a way that its value gets included in bookmarks. This means that when a user creates a bookmark the value of OnApplyBookmark is stored within that bookmark. When the user applies the bookmark, the value of OnApplyBookmark is written back into the actual variable. Because we have set a Run Macro action on the OnInput event of the variable, our code gets fired the moment the value is written to the variable.
This example show how you can execute macro code when a bookmark has been applied. But, as mentioned before, you can also use this to trigger any available action.




Barry said,
Excellent tip, good to see some activity again on the “old man” of QlikView blogs
Cheers,
Barry
Gilles said,
Hey Barry,
Bedankt voor je reactie. ‘t is eigenlijk Bas die er weer leven in blaast. Bas zocht een platform om wat van z’n ideeen te delen en ik ben meer dan blij dat hij dat op QQQ wil doen.
Gr,
Gilles
Bas said,
Thanks for your reaction Barry.
Just like Gilles explains it is the same blog, but just an extra author. I’ll do my best to do some more posts in the future. It’s great to have the opportunity to post on QQQ!
- Bas
Add A Comment