Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikWorld 2020: Join us May 11 - 14, 2020 in Phoenix, AZ. Register early and save $400. Learn More
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
MVP & Luminary
MVP & Luminary

Re: script error when combine SubStringCount and Concat function in IF staement

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
MVP & Luminary
MVP & Luminary

Re: script error when combine SubStringCount and Concat function in IF staement

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

Not applicable

Re: script error when combine SubStringCount and Concat function in IF staement

Thank you Gysbert, the solution works perfect!

Not applicable

Re: script error when combine SubStringCount and Concat function in IF staement

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

MVP & Luminary
MVP & Luminary

Re: script error when combine SubStringCount and Concat function in IF staement

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

Re: script error when combine SubStringCount and Concat function in IF staement

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

MVP & Luminary
MVP & Luminary

Re: script error when combine SubStringCount and Concat function in IF staement

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
Highlighted
Not applicable

Re: script error when combine SubStringCount and Concat function in IF staement

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!