Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Macro script: Count current selected values in field

I'm currently using a macro with an if statement that goes like this:

if ActiveDocument.Fields("%VIEW_NAME").GetSelectedValues.count > 0 then

ActiveDocument.Fields("PB_User_Flag").Lock

  ActiveDocument.Fields("MASTER_ID").Lock

end if

Yet, when the macro is triggered, the above fields are not locking. Any insights??

7 Replies
Anonymous
Not applicable
Author

the condition is true? did you try msgbox to test?

the Syntax Looks good. I made a small example (without condition ) and the field is locked

Not applicable
Author

If i test with a text box in the dashboard GetSelectedCount(%VIEW_NAME), the result is 1. But when I test with a msgbox in the macro script, nothing appears. Not sure what is missing here.

Anonymous
Not applicable
Author

try as first Expression in macro

what is the result? if not 1 then check your field

msgbox ActiveDocument.Fields(("%VIEW_NAME").).GetSelectedValues.count 

I tested with same condition and for me it works!

Not applicable
Author

Very strange, the message box comes up as 1, but then nothing locks.

Anonymous
Not applicable
Author

can you lock the fields with button "lock"?

marcus_sommer

I think you need to create at first an object and could then query the count:

dim doc, myField

doc = ActiveDocument

set myField = doc.GetSelectedValues

' msgbox myField.count 'optional for check

if myField.count > 0 then

  doc.Fields("PB_User_Flag").Lock

  doc.Fields("MASTER_ID").Lock

end if

- Marcus

rubenmarin

Hi, If you set the lock otuside the If(), it works?