Qlik Community

QlikView Documents

Documents for QlikView related information.

How to store and recover variables

Employee
Employee

How to store and recover variables

The example file shows how to fetch existing variables in a QVW file, and how to restore them back.

The storage of current variables can be done form a QlikView Project (PRJ) folder or directly from a QVW file.

The variables are store with their calculated values, not with the actual definition. To stored variable definition the variable has to be defined as a text. This can be done by using the SET definition.

Variables defined with SET can be later evaluated by dollar expanding the variable. In the "Store and recover variables - QVW file.qvw" a variable gets the text now(), so the variable will not have the actual timestamp of reload.

SET vNow = now()

The now() will be evaluated as soon as it is dollar expanded into a expression

context. See applicaiton text object for example.

=$(vNow)

So in summary, to make the variable definitions truly exportable, you might need to alter your variable definition strategy.

EDIT: The sample was updated to include also Rob's suggestion from comments below.

Attachments
Comments
MVP & Luminary
MVP & Luminary

Great idea! I think you may be able to simplify by not requiring a -prj folder and just load direct from the qvw like this:

LET vDocumentPath = documentpath();

LOAD

  [Name] as VariableName,

  [RawValue] as VariableValue

FROM  $(vDocumentPath) (XmlSimple, Table is [DocumentSummary/VariableDescription]);

You can  pick up the VariableValues as well in the LOAD. If you need "fresh" values -- those set in the current script run -- you could still do the for loop as shown in your example.

Employee
Employee

That's an awesome improvement. Thanks Rob!

0 Likes
Not applicable

Excellent Thank you So Much!!!

Not applicable

THANKS DEAR!

0 Likes
Not applicable

Excellent

0 Likes
Partner
Partner

Rob,

Great idea, but looks like this approach does not work in QS...

Any suggestions how to handle it there?

VK

0 Likes
MVP & Luminary
MVP & Luminary

Hi Vladimir,

I can't think of any direct way in QS script to get the list of variables.  There may be something in branch.qlik.com.  I'm going to look into it, if I come up with any ideas I'll post back here.

-Rob

enriquerosbitec
New Contributor

Hi, I think there should be a way to access all the variables in a similar way it is done with one:

http://branch.qlik.com/#!/project/56728f52d1e497241ae697f8

GitHub - erikwett/qsVariable: Variable extension for Qlik Sense

I launch this starting point for anyone able to do it 

Regards,

Enrique

http://branch.qlik.com/#!/project/56728f52d1e497241ae698b9

https://github.com/ralfbecher/QlikView_Extension_VariablesTableEditor

0 Likes
Employee
Employee

What is the use case for extracting variables in Qlik Sense? In what scenario is this required?

0 Likes
MVP & Luminary
MVP & Luminary

A typical case would be to move the variables to the script or an external file for reuse.

0 Likes
Version history
Revision #:
1 of 1
Last update:
‎2014-09-24 11:19 AM
Updated by: