Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
anguila
Partner - Creator
Partner - Creator

Store set analysis expression in the script

Hi,

I want to store and if statement expresion (containing set analysis) into a variable in the script for the future usage in expressions in some charts.

As the expression is the same in many charts is better having the same expresion in a variable for its future modifications.

I already defined that variable in the trigger section when the script finishes its reload. But for some reasons (developement flexibility, user scalability, all params together, etc..) I have to move into the script.

So my question exactly is: "How can I set a variable with this expresion in the script?":

     =if(Customer='Custom1',Only({1<IdField={TYPE1'}>} Method), Only({1<IdField={'TYPE2'}>} Method))

I tried let with no luck..

Thanks!

David.

1 Solution

Accepted Solutions
anguila
Partner - Creator
Partner - Creator
Author

I solved it!

The problem was so silly.. the issue was with the single quotes of the set analysis, so I just surrounded it the expression with double quotes and it worked like a charm:

SET vExpre = "if(Customer='Custom1',Only({1<IdField={TYPE1'}>} Method), Only({1<IdField={'TYPE2'}>} Method))";

David.

View solution in original post

5 Replies
daveamz
Partner - Creator III
Partner - Creator III

Hi David,

     Try SET vExpre = 'if(Customer='Custom1',Only({1<IdField={TYPE1'}>} Method), Only({1<IdField={'TYPE2'}>} Method))';

     or

     SET vExpre = '=if(Customer='Custom1',Only({1<IdField={TYPE1'}>} Method), Only({1<IdField={'TYPE2'}>} Method))';

     I tried the first variant and it works for a simple expression as field1+field2

Regards,

David

anguila
Partner - Creator
Partner - Creator
Author

It doesn't work at all..

If I set the expression of a text object as: =vExpre the result is 'if(Customer='Custom1',Only({1<IdField={TYPE1'}>} Method), Only({1<IdField={'TYPE2'}>} Method))'

And when I try to access the value (expresion: =$(vExpre) the result is -

When I added this expression as a trigger or even as a variable, and I set the expresion of the text object as =vExpre, the result is the expresion WITHOUT quotes: if(Customer='Custom1',Only({1<IdField={TYPE1'}>} Method), Only({1<IdField={'TYPE2'}>} Method))

Any idea? I tried the both ways you said (with and without the equal).

Thanks for the reply!

anguila
Partner - Creator
Partner - Creator
Author

I solved it!

The problem was so silly.. the issue was with the single quotes of the set analysis, so I just surrounded it the expression with double quotes and it worked like a charm:

SET vExpre = "if(Customer='Custom1',Only({1<IdField={TYPE1'}>} Method), Only({1<IdField={'TYPE2'}>} Method))";

David.

marcelo_7
Creator
Creator

I have a similar problem only that my expression uses both ' and ", any ideas?

num((1 - (sum({<DATUM={">=$(v7daysBack)<=$(v1dayBack)"}>}_Brist) / (sum({<DATUM={">=$(v7daysBack)<=$(v1dayBack)"}>}_Brist)+sum({<DATUM={">=$(v7daysBack)<=$(v1dayBack)"}>}_EJ_Brist))))*100,'##,0', ',')

anguila
Partner - Creator
Partner - Creator
Author

try to replace the double quotes inside your expresion with chr(34), the same value in the ascii table.