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 else expression in Tmap : ERROR

Hello,

 

I've search this forum for 2 days to get the syntax for my variable down.

When launching my job however, my tmap is in error.

 

My expression:

 

(in_row.ColumnA.equals ("YES") && in_row.ColumnB("NO")) ? "1":
(in_row.ColumnA.equals("NO") && in_row.ColumnB.equals("YES"))? "2": ""

 

ColumnA and ColumnB are string. And I want to create a new out column that has 3 values  depending on columnA and columnB values: 1, 2 or empty.

 

Can someone give me any pointers on how to proceed from here ?

 

Thank you in advance!

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Yes, Always we should eye to avoid null pointer exception @uganesh 

View solution in original post

8 Replies
Anonymous
Not applicable
Author

initially check either columnA  or columnB not equal to null. As we don't want both nulls in two columns

then

write this expression as per your requirement

(in_row.ColumnA.equals ("YES") && in_row.ColumnB("NO")) ? "1":

"2"

 

Anonymous
Not applicable
Author

Adding to that am assuming in columns a and column b we have only yes, no and null, Please confirm it 

Anonymous
Not applicable
Author

Yes , the values in those columns are either yes, no or null
Anonymous
Not applicable
Author

Then you will have mutiple combinations

ColumnA    ColumnB

null         yes

yes         null

null         no

no         null

no         yes

yes        no

no         no

yes       yes

 

Even if you want to populate only the value for your chosen combination before as below, you should one particular value with string you chosen its an empty  string which is fine, but you should check  the condition  columnA  or columnB not equal to null, that means both not equal to null , but its not required if you want to use a specific combination as below you can set all values to empty string

(in_row.ColumnA.equals ("YES") && in_row.ColumnB("NO")) ? "1":
(in_row.ColumnA.equals("NO") && in_row.ColumnB.equals("YES"))? "2"

:

""

But use below 

function , you did not write in_row.columnB.equals("No") may be that caused problem

 

But 

use below function 

(in_row.ColumnA.equalsIgnoreCase("YES") && in_row.ColumnB.equalsIgnoreCase ("NO")) ? "1":
(in_row.ColumnA.equalsIgnoreCase("NO") && in_row.ColumnB.equalsIgnoreCase("YES"))? "2"

:

""

 

Please give kudos if it solves your issue and accept as solution

 

akumar2301
Specialist II
Specialist II

I agree with Manish. Just To avoid null pointer

Use (“yes”).equalIgnoreCase(row1....)

Instead of
in_row.ColumnA.equalsIgnoreCase("YES")

In this case if any of two column is null , output will be “”
Anonymous
Not applicable
Author

Yes, Always we should eye to avoid null pointer exception @uganesh 

Anonymous
Not applicable
Author

I am currently testing this expression. 

 

Crossing my fingers it works..

akumar2301
Specialist II
Specialist II

If it worked , please make this topic as resolved. It helps others.