Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
hugmarcel
Specialist
Specialist

How to set variable as read-only via macro or in script?

Hi

Is it possible to mark a variable as read-only, either via macro or in script?

I have about 10'000 variables in Document properties -> Variables, and do not like to scroll throuth all of them to set the attribute manually.

See as well https://community.qlik.com/thread/24463

Thx - Marcel

1 Solution

Accepted Solutions
marcus_sommer

See this adjusted example from APIGuide.qvw for read only:

set v = ActiveDocument.Variables("Variable1")

prop = v.GetProperties

prop.ConstraintsFlag = 4     'read only

v.SetProperties prop

and this here is an example how to loop through the variables:

set vars = ActiveDocument.GetVariableDescriptions

for i = 0 to vars.Count - 1

    set v = vars.Item(i)

    msgbox(v.IsConfig)

next

- Marcus

View solution in original post

3 Replies
marcus_sommer

See this adjusted example from APIGuide.qvw for read only:

set v = ActiveDocument.Variables("Variable1")

prop = v.GetProperties

prop.ConstraintsFlag = 4     'read only

v.SetProperties prop

and this here is an example how to loop through the variables:

set vars = ActiveDocument.GetVariableDescriptions

for i = 0 to vars.Count - 1

    set v = vars.Item(i)

    msgbox(v.IsConfig)

next

- Marcus

HirisH_V7
Master
Master

Hi ,

like this,

alternatively add this to your macro code,

set macroVariable = ActiveDocument.GetVariable("yourVariableName")

then use marcroVariable.GetContent.String to retrieve the variable's contents

HTH,

Hirish

HirisH
“Aspire to Inspire before we Expire!”
hugmarcel
Specialist
Specialist
Author

Great! Thank you!