OnApplyBookmark document event trigger

Posted by Bas on 28/09/2011 under How To | 3 Comments to Read

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?

My first hunch in solving this was to simply use a field event trigger. But when you setup an OnSelect trigger on a field, it only fires when the user makes a manual selection in the field. The trigger will not fire when the user changes the field selection by applying a bookmark.
Fortunately it possible to mimic the OnApplyBookmark trigger behavior by using a variable event trigger. To make this happen I use the option to include the value of the variable in a bookmark together with a variable event trigger. The following steps describe how this works.
Start off by adding a variable to the Variable Overview (CTRL-ALT-V) with the name OnApplyBookmark and set its value to any piece of text. In this example I have used the text true (see the image below).

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).

Click on the Edit Module… button to add the code below to the macro editor.

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

Get Adobe Flash player