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

Why do variables lose their contents?

Does anyone know why variables lose their contents? e.g. I have a variable which has a formula

=' Email : ' & EmailAddress

I have a macro (launched via a button) which uses the content of this variable. For some reason the contents of the variable gets cleared and the formula is lost.

1 Solution

Accepted Solutions
Not applicable
Author

What I eventually did was to delete the bookmarks I was using.

Then fill in the formula's I needed in the variables.

Then create the bookmarks again

Activate the new bookmarks via the buttons.

This for the time being seems to have stopped the formulas from being deleted from the variables

View solution in original post

5 Replies
magavi_framsteg
Partner - Creator III
Partner - Creator III

Hi MarkBoomer.

I don't know how you declared your variable, and the variable behaves differently depending on how it was declared.

LET variable1 = something;

vs.

SET variable2 = something else;

LET variables are first evaluated, then the evaluated expression is stored into the variable.

SET variables: The expression itself is stored in the variable and behaves like a dynamic variable which gets updated when for example your selections change.

Try and always declare variables in the script, not in the GUI variable overview.

Hope this helps.

Kind regards

Magnus Åvitsland

BI Consultant

Framsteg Business Intelligence Corp.

Not applicable
Author

Magus

I should have mentioned the variables are created in

SETTINGS | DOCUMENT PROPERTIES | Variables Tab

Then I enter the formula in the value field.

I select a row in a table and have a button which executes a macro which retrieves the value of the variable and then uses it to fill in the email address in an email in Outlook. I do it this way as I couldn't find a way to directly enter QlikView fields into macros.

magavi_framsteg
Partner - Creator III
Partner - Creator III

Hi again MarkBoomer.

Here are some macro code examples on how to get/set fields/variable content:

GetVariableValue:

SET vMacroVar = ActiveDocument.Variables("NameOfDocumentVariable")

vMacroVar.GetContent.String

SetVariableValue:

SET vMacroVar = ActiveDocument.Variables("NameOfDocumentVariable")

vMacroVar.SetContent "ValueToSet", True

GetFieldValue:

ActiveDocument.Fields("FieldName").GetSelectedValues.Item(0).Text

SetFieldValue:

ActiveDocument.Fields("FieldName").select "ValueToSet"

Kind regards

Magnus Åvitsland

BI Consultant

Framsteg Business Intelligence Corp.

Not applicable
Author

Magnus

Thats similar to what I'm using in the macro to get the value of the variable. The problem is that the variable is set already in the Document settings and the macro retrieves the value.

The problem is that by the time the macro retrieves the variable the contents (i.e. the formula which creates the value) has been cleared.

Not applicable
Author

What I eventually did was to delete the bookmarks I was using.

Then fill in the formula's I needed in the variables.

Then create the bookmarks again

Activate the new bookmarks via the buttons.

This for the time being seems to have stopped the formulas from being deleted from the variables