Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
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??

Tags (2)
7 Replies
hrlinder
Honored Contributor

Re: Macro script: Count current selected values in field

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

Re: Macro script: Count current selected values in field

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.

hrlinder
Honored Contributor

Re: Macro script: Count current selected values in field

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

Re: Macro script: Count current selected values in field

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

hrlinder
Honored Contributor

Re: Macro script: Count current selected values in field

can you lock the fields with button "lock"?

Re: Macro script: Count current selected values in field

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

Re: Macro script: Count current selected values in field

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

Community Browser