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

Announcements
Save an extra $150 Dec 1–7 with code CYBERWEEK - stackable with early bird savings: Register
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] Nested If-Else block

Hi All,
I have recently started working on Talend and need some help to implement the below logic :
If (Field1 is null)
{
  If (Length(Field2)>0)
   {
      Field2
   }
  else
    {"ABC"  }
}
else
{
If (Length(Field3)>0)
   {
      Field3
   }
  else
    {"ABC"  }
}
I have used the operators in talend to code this but somehow keep coming up with the null pointer exception. Please help .

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

It likely is caused by a null Field2. Always check for null before doing any other check. Try this....

OUT2.FIELD1 == null ? ((OUT2.FIELD2!=null && OUT2.FIELD2.length() > 0) ? OUT2.FIELD2 : "OTHER")  : ((OUT2.FIELD3!=null && OUT2.FIELD3.length() > 0) ? OUT2.FIELD3 : "OTHER") 

View solution in original post

3 Replies
Anonymous
Not applicable
Author

You can use in-line IFs for this. Something like below....

Field1 == null ? Field2.length()>0 ? Field2 : "ABC" : Field3.length()>0 ? Field3 : "ABC"
Anonymous
Not applicable
Author

Tried using the statement below:
OUT2.FIELD1 == null ? (OUT2.FIELD2.length() > 0 ? OUT2.FIELD2 : "OTHER")  : (OUT2.FIELD3.length() > 0 ? OUT2.FIELD3 : "OTHER") 
But I keep getting a Java exception. Is it an issue with the length() function being used with a Null value coming fro Field2 or Field3 or is there something wrong with the way I'm writing the expression ?
Anonymous
Not applicable
Author

It likely is caused by a null Field2. Always check for null before doing any other check. Try this....

OUT2.FIELD1 == null ? ((OUT2.FIELD2!=null && OUT2.FIELD2.length() > 0) ? OUT2.FIELD2 : "OTHER")  : ((OUT2.FIELD3!=null && OUT2.FIELD3.length() > 0) ? OUT2.FIELD3 : "OTHER")