Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

script error when combine SubStringCount and Concat function in IF staement

Hello,

I try to use bellow statement to decide if load a table into the document in script.

IF(SubStringCount(Concat(%DIM_LOADING_SERIES, '|'), 'XREF_Product_Master')>0) THEN

.........;

ENDIF

While I got error message shows,

"Script line error

IF(SubStringCount(Concat(%DIM_LOADING_SERIES, '|'), 'XREF_Product_Master')>0) THEN"

I do have the DIM_LOADING_SERIES loaded and selected in the front-end, then what could be the reason for error?

2014-10-25 19-34-45.jpg

Thanks a lot!
Alex
1 Solution

Accepted Solutions
Gysbert_Wassenaar

You can reference fields directly in aggregation functions only in load statements, not in if-then blocks. You can do it this way:

Temp:

LOAD substringcount(concat(%DIM_LOADING_SERIES, '|'),'XREF_Product_Master') as TestResult

RESIDENT DIM_LOADING_FILES;

IF (peek('TestResult')) THEN

     // do stuff

ENDIF


talk is cheap, supply exceeds demand

View solution in original post

7 Replies
Gysbert_Wassenaar

You can reference fields directly in aggregation functions only in load statements, not in if-then blocks. You can do it this way:

Temp:

LOAD substringcount(concat(%DIM_LOADING_SERIES, '|'),'XREF_Product_Master') as TestResult

RESIDENT DIM_LOADING_FILES;

IF (peek('TestResult')) THEN

     // do stuff

ENDIF


talk is cheap, supply exceeds demand
Not applicable
Author

Thank you Gysbert, the solution works perfect!

Not applicable
Author

Hi Gysbert,

I have to continue with this question a little bit more.

Please see attached image, here I create several list boxes which allow users to make selections, user pick the selection and assign a value to a variable.

For example, vDIMXref (I create this variable in user interface), when I select XREF_Product_Master in list box,  then vDIMXref get 1.

Then I want to use this variable in script to decide if load table 'XREF_Product_Master' or not, here I can not succeed, I got a error message in attached image.

2014-10-26 23-47-51.jpg

2014-10-27 00-05-25.jpg

Gysbert_Wassenaar

It looks like your variable vDIMXref contains an = sign in front of the expression. If that's correct you need to remove it.


talk is cheap, supply exceeds demand
Not applicable
Author

when I remove the '=' sign, then the variable does not work, I define them in front end, then I need a '=' to calcuate value

2014-10-27 12-36-04.jpg

2014-10-27 12-36-30.jpg

2014-10-27 12-29-09.jpg

Gysbert_Wassenaar

I don't think I said to remove the = sign from all your variables. But you will have to remove it from the expression in vDIMXref


talk is cheap, supply exceeds demand
Not applicable
Author

Hi Gysbert, from your solution to wava1978 (http://community.qlik.com/thread/65816), this is exactly the reason for my issue, perfect solution, thank you very much!