Here is what QlikTech says about macro in the reference manual.
82.2 Macro functionality limitations
Functionality that will normally work well in macros in the QlikView Server environment with any type of
l Logical operations such as clearing or selecting in fields
l Operations related to variables
The following types of functionality are not to be used in the QlikView Server environment , as they may
cause unexpected results:
l Layout operations acting on the properties of sheets and sheet objects via SetProperties
l Operations changing document or user settings
l All operations related to the script, including Reload
l Data reduction operations, e.g. ReduceData
l Operations such as Save and Open document
And thus your macro will not work over browser.
If you set up this property initially in the QV application and save it, it should keep this property, unless there is a chance that after reload the filed in question may end up empty. Or if you remove all data. So, in "normal" situation you don't need to set it up dynamically.
I can only add that this macro should work in IE Plugin. Frankly I'm trying to avoid using macros altogether because of AJAX.
For my dashboard, I need to force unique values on some tabs and not on others. So, I've devised a work-around as follows:
- I added a variabled (vForceOne) that is set to true/false when the tab requiring one and only one field selection is entered/exited.
- I modified my macro to be the following:
SUB AlwaysOneProductSelected() IF (ActiveDocument.Variables("vForceOneProduct").GetContent.string = "True") THEN SET fld = ActiveDocument.GetField("Product Name") SET selections = fld.GetSelectedValues IF (selections.Count = 0) THEN selectionText = "Product X" ELSE selectionText = selections.Item(0).text END IF fld.Select selectionText END IF END SUB
3. I added a trigger to the product field to fire the macro whenever the selection is changed.
In essense, my macro is now providing the functionality that would usually be provided by the OneAndOnlyOne field property. The only problem is that the macro doesn't fire when shift+click selection is used. (See http://community.qlik.com/message/329011.)