Loading Variables From Another QVW

I just read a good post by Kamal Kumar Sanguri on QlikCommunity.  Kamal’s post reminded me that managing variables in QlikView has always presented some challenges and over the years various techniques and code snippets have been shared to address those challenges.

Most folks quickly find that maintaining variables in external files  loaded with a script loop is a good approach and resolves common concerns regarding shareability, dollar sign escaping and so on.

Sometimes you encounter a need for an adhoc import or export of variables. Kamal’s post offers some useful code snippets for that.  Several years ago my colleague Barry Harmsen  wrote a post on QlikFix.com that shows some useful macros to manipulate Variables.  Barry and I  subsequently collaborated on a desktop utility that handles both import and export from a menu.  While the download link on the blog is dead, I’ve reposted the utility on the QlikViewCookbook Tools section for download.

Kamal said that there is no way to directly load variables from one QlikView document to another.  That got me to thinking.  It is possible, but gee, no one has ever asked for it.

What’s the use case?  When I want to do an adhoc copy, I use the desktop utility referenced above.  I have seen a number of customers who generate complex calendars into QVDs followed  by  generation of variable for use with the calendar.  Calendar QVD consumers incorporate the variable generation logic with an include file. It works.

Would it be any better if calendar consumers loaded the variables directly from the calendar generating QVW?  I think not because there is possibility of a mismatch between the QVW source and the Calendar QVD.

All that said, maybe you have a use case for loading variables from a QVW?  No one asked, but for the record here is the script to load variables directly from another QVW.

FROM [..\..\data\StudentFile.qvw] 
(XmlSimple, Table is [DocumentSummary/VariableDescription])
Where IsConfig = 'false' and IsReserved = 'false' // Exclude system vars
// Any addtional filtering here

FOR idx=0 to NoOfRows('VariableDescription')-1
 LET vVarname = Peek('Name',$(idx),'VariableDescription');
 LET [$(vVarname)] = Peek('RawValue',$(idx),'VariableDescription');
NEXT idx

SET idx=;
SET vVarname=;
DROP Table VariableDescription;

Happy Scripting!





9 thoughts on “Loading Variables From Another QVW”

  1. It is pretty useful to load meta-data for all apps, like application-owner, version, description, etc . You only need to agree on certain standards, but then you may create a (fully automatic) table of content of all your applications, along with infoon last refresh, errors, etc.
    I used this a lot.

    Rgds Peter

  2. Brilliant!!!
    could it be, there is something similar for triggers? dimension lists?
    kind regards,

    1. Yes, you can load all kinds of info from a QVW including triggers and Dimensions. Open the QVW with the table files wizard and chose xml as the file type. You’ll be able to see all the available xml tables that provide rich metadata.

  3. Is there a way to load variables from another QVF?

    With the above script ia can be able to pull all the variables from one QVW to QVW/QVF. But I was wondering is there a way to load variables from one QVF to another QVF.

    1. I don’t know of any way to load variables directly from a QVF using script. You could extract them first and load from the extract file.

    2. On second thought…you could use the QsAppMetaConnector that is part of QS Document Analyzer.

  4. Hi Rob

    We’ve been using this code for over a year now within QLik Sense, however we just upgraded to the Nov 2018 release and it suddenly stopped

    We are now getting a script error simple saying


    Script Error occuried here :

    We don’t know what to do !!

    1. Hi Mike,
      I just tested using QS Feb 2019 loading from QVWs saved in QV Nov 2018. No error for me. What is the error within the script log?

Leave a Reply

Your email address will not be published.