Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

String Method syntax in tMap Expression for Two seperate columns values have to have two distinct values for a seperate column to have a True or False Value

I am wondering how I can nest a if then else statement based off of two separate values in the two different columns So a different column would have a True or False Value.

This is a typical If then else string method in java

column1.equals("Home Phone")? "True":"False"

If I wanted to add another column with a distinct value would the syntax be

column2.equals("Fax") && column1.equals("Home Phone")? "True":"False"

 

I'm in early development of a job and can't run the job yet, so just making sure the syntax is right from the start.

 

Let me know,

 

Thanks,

 

Andrew

Labels (3)
7 Replies
TRF
Champion II
Champion II

You are near to the solution but take care of null values. The following syntax is better:
"fax".equalsIgnoreCase(row1.column2)
If row1.column2 is null the expression evaluates to false but doesn't generates a null pointer exception.
TRF
Champion II
Champion II

@sm In response to your question by PM, the complete syntax should looks like this:

"fax".equalsIgnoreCase(row1.column2) && "home phone".equalsIgnoreCase(row1.column1) ? true : false
Anonymous
Not applicable
Author

@TRF 

 

This String Expression that's similar to yours only returns False Values currently. 

 

"Do Not Mail".equalsIgnoreCase(row1.mailpref1)&& "Do Not Mail".equalsIgnoreCase(rmailpref2)&& "Do Not Mail".equalsIgnoreCase(mailpref3)? "True" : "False"

 

If any of these rows contain the "Do Not Mail" value set the value as True else "False"

 

So not all three values in three seperate columns contains "Do Not Mail" value just one column has to contain "Do Not Mail" value

 

Maybe you were under the impression that I wanted every column in the string method to have the value "Do Not Mail" not just one.

 

Please advise

 

-Andrew

 

 

akumar2301
Specialist II
Specialist II

"Do Not Mail".equalsIgnoreCase(row1.mailpref1) ||  "Do Not Mail".equalsIgnoreCase(rmailpref2) || "Do Not Mail".equalsIgnoreCase(mailpref3)? "True" : "False"

 

note : True" and true are not same. 1st one is string another is boolean.

Anonymous
Not applicable
Author

Hello @uganesh

 

If I had some dirty data in the column like addresses how would I add the additional logic to change every value that is not "Yes" to "No"

This is for a different column in the same input data I have a do not contact column.

 

row1.donotcontact.equals("Yes")? "True": "False"

 

This returns other data besides "True and "False" including blanks

Anonymous
Not applicable
Author

I meant to change the value to "FALSE" not "No" to clarify

akumar2301
Specialist II
Specialist II

Your expression looks correct.
Donotcontain equals to yes , then true else false.

To avoid null issue try like this
“Yes”.equals(row1.donotcontact)? "True": "False"

This should not ideally give othervalue than True and False.

Can you give some example when you getting blanks or other values ?