Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Nesting variables in the script

Hello,

I'm having difficulty getting nested variables and parameters working correctly in the load script.

Here is the script that I'm using:

TestData:

LOAD * Inline

[

          Key, Value

          ABC, 1

          DEF, 2

          GHI, 2

          JKL, 3

];

set vTestFor1 = (Value=1);

set vTestFor2 = (Value=2);

set vTestFor3 = (Value=3);

 

set vCalcFor2=if($(vTestFor2), 'Y', 'N');

set vCalcForXScript=if($(vTestFor$1), 'Y', 'N');

vCalcForXScript doesn't work - it translates the inner variable at load time. If I set the same value within the Variable Overview, it does work, though.

I've attached an example that shows the problem. vCalcForXOverView has been set in the Variable Overview and the chart shows it is working.

How do I get the same effect, but by setting vCalcForXScript in the script?

Thanks,

-Ken

1 Solution

Accepted Solutions
Gysbert_Wassenaar

Option 1:

let vCalcForXScript= 'if($' &'(vTestFor$1),' & chr(39) & 'Y' & chr(39) & ','  & chr(39) & 'N' & chr(39) & ')';

Option 2:

set vT =if(@(vTestFor@1), 'Y', 'N');

let vCalcForXScript = replace('$(vT)', '@','$');


talk is cheap, supply exceeds demand

View solution in original post

4 Replies
bgerchikov
Partner - Creator III
Partner - Creator III

Hi Ken,

The problem is $ sign in vTestFor$1

set vCalcForXScript=if($(vTestFor1), 'Y', 'N');

the script considers vTestFor$1 as a different variable, which is null.

Thanks!

Not applicable
Author

Hi Boris,

The $1 is intentional as I want to be able to specify which function is called based on a parameter.

 

For example: If vCalcForXScript is: if($(vTestFor$1), 'Y', 'N');

Then in a chart, the following call would go through the translations:

 

          $(vCalcForXScript(2))                     // original call

          if($(vTestFor2), 'Y', 'N');          // substitute vCalcForXScript

          if((Value=2), 'Y', 'N')                    // substitute vTestFor2

 

Alternatively I could use: $(vCalcForXScript(3)) which would use the vTestFor3 variable.

 

My problem is that if I were to set vCalcForX using the Variable Overview interface, it will work. If I attempt to set vCalcForX in the load script (as per the first post) it translates the variables immediately. (as you pointed out)

 

I'm looking for a way to set vCalcForX to contain variables without translating them until later.

 

Thanks,

 

-Ken

Gysbert_Wassenaar

Option 1:

let vCalcForXScript= 'if($' &'(vTestFor$1),' & chr(39) & 'Y' & chr(39) & ','  & chr(39) & 'N' & chr(39) & ')';

Option 2:

set vT =if(@(vTestFor@1), 'Y', 'N');

let vCalcForXScript = replace('$(vT)', '@','$');


talk is cheap, supply exceeds demand
Not applicable
Author

Thanks Gysbert.

It may not be pretty, but the second one worked like a charm.