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.

VariableDescription:
LOAD 
 Name,
 RawValue
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!

-Rob

 

 

Share

7 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,
    Emma

    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.

Leave a Reply

Your email address will not be published. Required fields are marked *