Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Setting OneAndOnlyOne Dynamically

For one tab in our dashboard, it is a requirement to have the Product Name field's OneAndOnlyOne property set to true. Therefore, I've written a macro that fires on the sheet's OnActivateSheet trigger. The macro looks like this:

SUB AlwaysOneSelected()
    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
   
    SET fprop = fld.GetProperties
    fprop.OneAndOnlyOne = True
    fld.SetProperties fprop
END SUB

This works just as intended in my developer copy of the dashboard. The OneAndOnlyOne property is set when I enter the tab, so I must always have exactly one selection in the Product Name field. If I switch to WebView in my development environment, it still works as expected.

Unfortunately, when the QVW is posted to our server, this functionality breaks, regardless of whether we use the IE plugin or the standard webview in other browsers. I know that the macro is successfully triggered because if I enter the tab with no selection in the Product Name field, Product X gets selected. Yet, the OneAndOnlyOne property is not set; I can clear the field or select multiple product names.

Any ideas? Could this be a bug?

1 Solution

Accepted Solutions
Not applicable
Author

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:

  1. I added a variabled (vForceOne) that is set to true/false when the tab requiring one and only one field selection is entered/exited.
  2. 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.)

View solution in original post

7 Replies
Anonymous
Not applicable
Author

I'd expect it to work in IE plugin but not in webview or other browsers.

Regards,

Michael

Not applicable
Author

Hi Michael,

Why wouldn't you expect this to work in all browsers?

Thanks,

Stephen

kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Dear Stephen,

     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

client is:

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.

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
Anonymous
Not applicable
Author

This macro is changing object properties.  Not something that I expect to work in AJAX.  The only relaible macros for AJAX are those that make selections and modify variables.

Regards,

Michael

Not applicable
Author

Thanks, Kaushik & Michael. Without using a macro, is there any way to change object properties at runtime? Any other way to get the desired behavior?

Anonymous
Not applicable
Author

Stephen,

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.

Regards,

Michael

Not applicable
Author

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:

  1. I added a variabled (vForceOne) that is set to true/false when the tab requiring one and only one field selection is entered/exited.
  2. 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.)