Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
DateTimeCreated (String) EnquiryUID (String) ChannelId (Integer) ClientId (Integer)
2018-07-16 00:56:46 037CA2E9-3860-4D45-9234-4894BC8F07FA 229
2018-07-15 23:48:00 1807158dc9a4a9047142ea8f06 296
Requirements:
case 1: If digits 2 to 8 of DateTimeCreated match digits 0 to 6 of EnquiryUID and ChannelId is 229 or 296, then ClientId is 0
case 2: If digits 2 to 8 of DateTimeCreated do not match digits 0 to 6 of EnquiryUID and ChannelId is 229 or 296, then ClientId is 9
case 3: else ClientId
This is the method in the routine IsGTX_EnquiryUID
public static boolean isGTX (String dateTimeCreated, String EnquiryUID){
String noSpacesDateTimeCreated = dateTimeCreated.replaceAll("\\D", "");
String dateTimeCreatedChar2to8 = StringUtils.substring (noSpacesDateTimeCreated, 2, 8);
String EnquiryUIDFirst6Char = StringUtils.substring(EnquiryUID, 0, 6);
if (dateTimeCreatedChar2to8.equals(EnquiryUIDFirst6Char)) {
return true;
}
else {
return false;
}
}
What I did so far is using the trinary operator in tMap, but it only works on one condition.
row1.ChannelId == 229?( IsGTX_EnquiryUID.isGTX(row1.dateTimeCreated, row1.enquiryUID)?0 :9):row1.clientId;
I tries to use if - else if - else in tMap, but it did not worked.
How to do this for 3 different conditions in tMap?
I am using Talend Data Management Platform v6.3.1
You can do this with an inline IF condition. As an example, if you have a condition like this....
if(myInValue==1){
myOutValue = "a";
}else if(myInValue==2){
myOutValue = "b";
}else if(myInValue==3){
myOutValue = "c";
}else{
myOutValue = "z";
}....you would represent it like this as an in-line IF....
myOutValue = (myInValue==1 ? "a" : myInValue==2 ? "b" : myInValue==3 ? "c" : "z")
Hi,
My suggestion will be to use a tjavarow for complex row level if-else condition operations. Even though you can do the same logic in tmap, you may have to to think about the readability of the conditions also.
Hi @rhall,
Your suggestion is good if I have one InValue, but the problem is that I have different requirements. You are suggesting:
myOutValue = (myInValue==1 ? "a" : myInValue==2 ? "b" : myInValue==3 ? "c" : "z")
I have two inValues
myOutValue = if (myInValueOne==1 || myInValueOne==2) and myInValueTwo ==3 ? "a":"b", else myOutValue;
myOutValue = ((myInValueOne==1 || myInValueOne==2) && myInValueTwo==3 ? "a" :"b")
Your pseudocode IF had an extra ELSE which would never be reached....
if (myInValueOne==1 || myInValueOne==2) and myInValueTwo ==3 ? "a":"b", else myOutValue;