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

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
gt0731
Contributor III
Contributor III

How do i use Talend If-then-else for diffrent cases.

Hello Team,
Greetings to all of You!
I am  trying to write this expression  into talend tmap component .  How to write this expression into tmap  component expression builder using ternary operator.

case when ='(00) PRE-PAID' then '00'when='(01) C.O.D.' then '(01) C.O.D'when='(02) EOM' then '02'when='10' then '(10) NET 10 DAYS'when='15' then '(15) NET 15 DAYS'when='21' then '(21) 2 % 30 NET 31'when='23' then '(23) 2% NET 30 DAYS'when='3' then '(3) CHECK'when='30' then '(30) NET 30 DAYS' else end as TCode



Thanks in Advance !

Labels (2)
10 Replies
Anonymous
Not applicable

something like
"00".equals(row.tCode) ? "(00) PRE-PAID" :
"01".equals(row.tCode) ? "(01) C.O.D" :
"02".equals(row.tCode) ? "(02) EOM" :
"Unknown"
I think you ought to be using a look-up rather than hard-coding this as an expression
gt0731
Contributor III
Contributor III
Author

First off, thanks for  conditional operator expression.
You did mention on lookup expression.How do i use lookup expression in talend BIG DATA suite .Example?
This is Updated expression  :
"(00) PRE-PAID" .equals(row.tCode) ?"00"  :
 "(01) C.O.D" .equals(row.tCode) ?"01" :
"(02) EOM". equals(row.tCode) ? "02"  :
"Unknown"
 
gt0731
Contributor III
Contributor III
Author

Hi ,
when using Your expression getting this error at  tmap component.
Error description is :
Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
XML_API_tXMLMap_1 cannot be resolved to a type
XML_API_tXMLMap_1 cannot be resolved to a type
Syntax error on token ""(00) PRE-PAID"", delete this token
at bigdata.account_ftp_write_copy_0_1.Account_FTP_Write_Copy.tSalesforceInput_1Process(Account_FTP_Write_Copy.java:1854)
at bigdata.account_ftp_write_copy_0_1.Account_FTP_Write_Copy.runJobInTOS(Account_FTP_Write_Copy.java:4176)
at bigdata.account_ftp_write_copy_0_1.Account_FTP_Write_Copy.main(Account_FTP_Write_Copy.java:4033)
gt0731
Contributor III
Contributor III
Author

Hi ta,
Is that possible to put null  check condition in expression . because i tried this :

row.tCode=null?null:row.tCode.toUpperCase()
&&
"(00) PRE-PAID".equals(row.tCode) ?"00"  :
 "(01) C.O.D".equals(row.tCode) ?"01" :
"(02) EOM".equals(row.tCode) ? "02" :
"Unknown"


Getting Following :
Java && Error The operator && is undefined for the argument type(s) string,boolean.
Anonymous
Not applicable

Hi
Yes, you can check null value in the expression, but you don't use the operator && correctly here. The correct syntax looks like:
condition1?(condition2?value if true:value if false): (condition3?value if true:value if false)
Regards
Shong
gt0731
Contributor III
Contributor III
Author

Hi shong,

is that ok ?
row.tCode=null?("(00) PRE-PAID".equals(row.tCode) ?"00"  :
 "(01) C.O.D".equals(row.tCode) ?"01") :
("(02) EOM".equals(row.tCode) ? "02" :
"Unknown")


I tried this using expression condition1?(condition2?value if true:value if false): (condition3?value if true:value if false).


Getting this error :
Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
XML_API_tXMLMap_1 cannot be resolved to a type
XML_API_tXMLMap_1 cannot be resolved to a type
Syntax error, insert ": Expression" to complete Expression
Syntax error, insert ")" to complete Expression
Syntax error, insert ";" to complete Statement
Syntax error on token "checked", = expected
Invalid character constant
Syntax error on token ")", delete this token
Anonymous
Not applicable

try this:
row1.tCode==null?null:("(00) PRE-PAID".equals(row1.tCode) ?"00"  :
("(01) C.O.D".equals(row1.tCode) ?"01" :
("(02) EOM".equals(row1.tCode) ? "02":"unKnown" )))
gt0731
Contributor III
Contributor III
Author

Thanks a ton shong . syntax worked for me 
Anonymous
Not applicable

The original solution that I gave is null-safe.
If your input is null, then the output is "Unknown" (or whatever you want it to be).
That is why the tests are "String".equals(row1.value) rather than row1.value.equals("String").
Personally, I'd use a look-up (CSV file, database or whatever).
This look-up contains: -
input,output
01,C.O.D
02,EOM
...
You can then join the look-up in your tMap.