Multiple If/case Statement in tMap Expression Builder

One Star

Multiple If/case Statement in tMap Expression Builder

I seem to be doing this all the time, whenever there is a simple IF I just put it in the Expression builder eg:
myValue == "test" ? "True" : "False"
Now if I want to have multiple if's in the expression builder I'm having to either create a separate method and call it from the expression builder or use a tJavaRow. Is there a way to do the following in the expression builder directly as it just seems overkill to go out to a separate method/tJavaRow:
if (myValue == "test"){
return "True";
}elseif(myValue == "something else"{
return "False";
}else{
return "True";
}
One Star cri
One Star

Re: Multiple If/case Statement in tMap Expression Builder

Hi,
the following expression should be equivalent to the IF statement you posted:
(myValue == "test") ? "True" :  (  ( myValue == "something else" ) ? "False" : "True" )

The complexer the if statement is, the harder this is to read / understand though :-(
Anyways, hope this helps!

Regards
Christian
One Star

Re: Multiple If/case Statement in tMap Expression Builder

Hello gabbs,
One thing you could do is : myValue == "test" ? "True" : (myValue == "something else")? "False" : "True" that would be a translation of your code above.
Hope it helps!
Highlighted
One Star

Re: Multiple If/case Statement in tMap Expression Builder

Aye someone was quicker Smiley Sad
One Star cri
One Star

Re: Multiple If/case Statement in tMap Expression Builder

Aye someone was quicker Smiley Sad

;-) only a few seconds ... but comforting, to see, that we are of the same oppinion!
One Star

Re: Multiple If/case Statement in tMap Expression Builder

IIF ( (ISNULL(LE_CD) AND (MD_SOURCE_SYSTEM_O='15' OR MD_SOURCE_SYSTEM_O ='16')), OPERATING_UNIT_ID, 
IIF ( (ISNULL(LE_CD) AND (MD_SOURCE_SYSTEM_O = '25' OR MD_SOURCE_SYSTEM_O = '28' OR MD_SOURCE_SYSTEM_O = '27')),
IIF(INSTR(OPERATING_UNIT_NAME_INV_LINE,'-',1) > 0, SUBSTR(OPERATING_UNIT_NAME_INV_LINE,1,(INSTR(OPERATING_UNIT_NAME_INV_LINE,'-',1)- 1))), 
LE_CD))..in talend

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch