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

Five Stars

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 !

Five Stars

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

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
Five Stars

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

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"
 
Five Stars

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

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)
Five Stars

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

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.
Community Manager

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

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
----------------------------------------------------------
Talend | Data Agility for Modern Business
Five Stars

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

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
Community Manager

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

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" )))
----------------------------------------------------------
Talend | Data Agility for Modern Business
Five Stars

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

Thanks a ton shong . syntax worked for me 
Five Stars

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

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.
Two Stars

Re: How do I use in Talend If-then-else for different cases. please help me

If

                Trim(( IF IsNotNull((ffr_dcconso_ref_initial.TITLE)) THEN (ffr_dcconso_ref_initial.TITLE) ELSE (""))) <> ""

then 

                if

                Trim(( IF IsNotNull((ffr_dcconso_ref_initial.TITLE)) THEN (ffr_dcconso_ref_initial.TITLE) ELSE (""))) = "1"

                then "MR"

                else               

else ""

 

--FLAG