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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Vicky2
Contributor
Contributor

If else statement throwing error

Hi All, 

 

I am trying to achieve if else statement in tMap as follows. Using 5.6.1 talend version

 

Condition 1. If status = P then print the following values MOD,STK,ALG

(Sub Condition is 

IF ALG is not null then print ALG then ignore ALG field completely.)

 

Expected output 

if STATUS =p and ALG is not null

MOD=Sample_module;STK=Sample_stk;ALG=test;

 

if STATUS =p and ALG is null

MOD=Sample_module;STK=Sample_stk

 

if STATUS not equal to p then blank

 

(STATUS ).equals("P")?
("MOD="+"Sample_module;"+ ";STK="+"Sample_stk;"+
((ALG != null)? ("ALG="+ ALG):--false): " "

 

Please help to achieve this.

 

 

Labels (2)
3 Replies
TRF
Champion II
Champion II

Based on your screen capture, as you're using a ternary condition, you need the "else" part.

General syntax is "your_condition ? then_part_expression : else_part_expression"

Also, at runtime a possible cause of null pointer exception is row2.STATUS is null.

So, start the condition with "P".equals(row2.STATUS) ? ...

Vicky2
Contributor
Contributor
Author

Thanks TRF,

 

Is there any other alternative way to achieve this without using the ternary operator. As in my requirement , I don't have the else part. 

 

If condition is not matching then the field should not be printed completely. So only If condition should be there.

 

Thanks

TRF
Champion II
Champion II

Into a tMap, ternary condition is the best way. Having an empty "else part" is authorized (cond ? "A" : " ").
This one is maybe not so far of what you expect:
("P" ).equals(row2.STATUS) ? "MOD= Sample_module;;STK=Sample_stk;" +
((row2.ALG != null) ? ("ALG="+ row2.ALG) : "") : ""