Purpose

This document is used to track the limits of Qlik’s variable scope within the script as well as changes made on the front end.

Tests

Subroutines

Observations:

  • Variables created before a subroutine can be changed within the subroutine.
  • Variables created before or inside a sub routine stay within the model.
  • Parameter variables are used within the subroutine but do not exist outside of the sub routine.
  • A variable created before a subroutine but is the name of a parameter, will hold the value of what it was before the sub routine after it completes.

*Note: Side comments are values of Trace result.


Set vBeforeSub = 'BeforeSub';
Set pParam = 'BeforeSub';

Sub Test(pParam)

    Trace -----------------------------------------------------vBeforeSub: $(vBeforeSub);   // Result: BeforeSub
    Trace -----------------------------------------------------pParam: $(pParam);           // Result: pParam
    
    SET vInSub = 'InSub';
    SET vBeforeSub = 'InSub';
    SET pParam = 'InSub';

EndSub;

Call Test('pParam');

Trace -----------------------------------------------------pParam: $(pParam);               // Result: BeforeSub
Trace -----------------------------------------------------vInSub: $(vInSub);               // Result: InSub
Trace -----------------------------------------------------vBeforeSub: $(vBeforeSub);       // Result: InSub   
    
exit script;

Script vs Front End

This test is to determine how a variable’s state is tracked between creation and changes between the script and front end.

Observations:

Test 1: Can a script variable be changed on the front end?
  • Variable cannot be changed through the app variable overview.
  • Variable can be changed through actions on the front end.
Test 2: Can a front end variable be accessed from the script?
  • Yes
Test 3: Can a front end variable be changed from the script?
  • Yes
  • The variable is also changed to a “script variable”.

Clearing Variables:

You used to be able to clear variables doing: vVariable=; However, that is no longer the case. To delete a variable completely, you will have to delete it from the variable overview.

Empty variables persist when duplicating an app.