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).
MsgBox(“A bookmark was applied”)
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.