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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

If Then syntax

Hi,

I'm having difficulty with If/Then expressions using two variables in tMap:

 

This example works:

 

when varTemp = "BBB" then "X" is output otherwise vartemp is output

 

vartemp =                 row1.MultiValue.split(";")[1] 

varSingleValue2 =     Var.vartemp.equals("BBB")?"X":Var.vartemp

 

This example doesn't, but the logic is the same:

 

vartemp =                 row1.MultiValue.split(";")[1] 

varSingleValue2 =    if (Var.vartemp == "BBB") {
                                       "X";
                                } else {
                                       Var.vartemp ;
                                } 

 

When I run the job I get the error:

Syntax error, insert "VariableDeclarators" to complete LocalVariableDeclaration

 

Could you explain where I am going wrong?

 

Many thanks,

Bob.

 

 

Labels (2)
1 Solution

Accepted Solutions
akumar2301
Specialist II
Specialist II

in Tmap expression multi-line expression will not work.

 

in Tjava/Tjavarow/flex

 

    if (Var.vartemp.equals("BBB")) {
                                SingleValue2 =       "X";
                                } else {
                                      SingleValue2 =       Var.vartemp ;
                                } 

View solution in original post

4 Replies
akumar2301
Specialist II
Specialist II

in Tmap expression multi-line expression will not work.

 

in Tjava/Tjavarow/flex

 

    if (Var.vartemp.equals("BBB")) {
                                SingleValue2 =       "X";
                                } else {
                                      SingleValue2 =       Var.vartemp ;
                                } 

Anonymous
Not applicable
Author

Ok, many thanks.

Bob.

TRF
Champion II
Champion II

You cannot have an "if" expression on the right side of an assignment.

That's the reason why the 1rst example works (using ternary operator) and the 2nd one doesn't.

Also, you should never use "==" to compare 2 strings, String.equals() and equalsIgnoreCase() methods are here for that.

 

Anonymous
Not applicable
Author

Ah, we've tried this one! And it helped, actually. But anyway, we had to think through all levels of development and maintenance... and few weeks ago we've asked ourselves how much does it cost to build a website, and we hired the separate dev team, so they started building mobile-friendly website from scratch. Of course, you can try to build an app by yourself. But would it be reliable enough?