Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
tommyl
Creator
Creator

Conditional load with exit script statement

Hello,

I have a table(switch) with single column(status) and it has value either 'true' or 'false'. 

I want my script to loaded if the value is only 'true' and to be not loaded if the value is 'false'. 

I wrote this in the editor:

LOAD status;

[switch]:
SELECT status
FROM [schema].[switch];

let vButton = fieldvalue(status, 1) ;
if (vButton='true') then

 

------ Load scripts-------

else
EXIT Script;
End If;

But this does not work. Anytime i load, it automatically exits script. 

Could you please help me on this issue?

Regards,

Tommy,

2 Solutions

Accepted Solutions
Kushal_Chawda

LOAD status;

[switch]:
SELECT status
FROM [schema].[switch];

let vButton = fieldvalue('status', 1) ;
if ('$(vButton)'='true') then

------ Load scripts-------

else
EXIT Script;
End If;

View solution in original post

Kushal_Chawda

There are two things

1) Fieldvalue function always  takes fieldname parameter with single quotes. Hence below is the one change require

fieldvalue('status', 1)

2) Ideally vButton= 'true' condition should work but wrapping variable within single quotes using $ expansion always works when comparing texts. So for safer side you can always use variable like '$(vButton)' when you need to compare texts. If you want to compare numeric then no need to use single quotes, you can refer the variable  like $(vButton)

Hope this is helpful

View solution in original post

13 Replies
tresesco
MVP
MVP

Try putting quotes around field name, like:

let vButton = fieldvalue('status', 1) ;

tommyl
Creator
Creator
Author

Thank you for your response. Unfortunately it did not work. 

Gabriel
Partner - Specialist III
Partner - Specialist III

Hi,

 

Can I suggest 

if $(vButton)='true'  then

 

------ Load scripts-------

else
EXIT Script;
End If;

 

 

Kushal_Chawda

try this 

LOAD status;

[switch]:
SELECT status
FROM [schema].[switch];

let vButton = fieldvalue(status, 1) ;
if ('$(vButton)'='true') then

------ Load scripts-------

else
EXIT Script;
End If;

 

tommyl
Creator
Creator
Author

I get this error:

The following error occurred:
Unexpected token: ')', expected one of: 'OPERATOR_PLUS', 'OPERATOR_MINUS', 'OPERATOR_MULTIPLICATION', 'OPERATOR_DIVISION', 'OPERATOR_STRING_CONCAT', 'like', 'and', ...
 
The error occurred here:
if ( = 'true'>>>>>>)<<<<<< then
 
tommyl
Creator
Creator
Author

Unfortunately Kush, it didnt work out either. Thank you for the response. 

Kushal_Chawda

LOAD status;

[switch]:
SELECT status
FROM [schema].[switch];

let vButton = fieldvalue('status', 1) ;
if ('$(vButton)'='true') then

------ Load scripts-------

else
EXIT Script;
End If;
tommyl
Creator
Creator
Author

Thanks Kush for the solution. It worked well.

Btw, I dont get the idea behind, if you have some short clue on that or a link to a document, could you pls share?

Kushal_Chawda

Sorry.  I did not get your request? Are you asking how this worked?