Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

tMap conditional formula

I am trying to write a condition in my tMap translation.  It is giving me an error when trying to run.  Essentially, I have a required field I am trying to populate on the Output.  From the input, I first want to check one of the columns for null.  If it is null, I want to use a different column to populate output.  Here is what I have written, not sure what I am missing:

 

row1.Field1 = null ? row1.Field2 : row1.Field1

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

@ksingh @nthampi @uganesh   Thank you all for your help!

I made a few adjustments and got it to work.  Here is the final expression I used:

row1.NAME != null && row1.NAME.trim().length() != 0 ? row1.NAME : row1.NUM

 

I really appreciate all of  your input.  I'm new to Talend and this is helpful.  This board is great. I will be now be a longtime user.

View solution in original post

14 Replies
Anonymous
Not applicable
Author

Also, I have tried comparing using = and ==.   Either way, I am getting an error when the first field is blank and it is not populating it the 2nd field. 

akumar2301
Specialist II
Specialist II

(row1.Field1 == null || row1.Field1.trim().length() == 0 )? row1.Field2 : row1.Field1

 
 
 
Anonymous
Not applicable
Author

@steeld95  the one which @uganesh  sent will work, even i used it before, specially when we have empties other then null it will be very helpful

Anonymous
Not applicable
Author

Thank you @uganesh.  It is now giving me a different error.  It is saying:

Token<END-OF-STATEMENT> was not valid. Valid tokens: ? : <FLOAT> <BIGINT> <DECIMAL>

 

It is all string fields.  The input fields are stings and the output field is a string.   

 

I appreciate your help!

Anonymous
Not applicable
Author

(row1.Field1 == null || StringHandling.LEN(row1.Field1)== 0 )? row1.Field2 : row1.Field1

akumar2301
Specialist II
Specialist II

 

Error looks unrelated.Can you please verify and confirm that , this error comes only with above expression.

Are you using any database Query before. usually these errors are databse related.

 

can you please give your job screenshots.

Anonymous
Not applicable
Author

@uganesh  the above function i mentioned just now may work, let @steeld95 try it and let us know

 

Please dont forget to give kudos and accept solution if it worked @steeld95 

Anonymous
Not applicable
Author

Hi,

 

    Seems you are trying to load the String value to a database like DB2 where the data is in different format.

 

    Could you please share the screen shot of the job flow and the component where it is erroring out? There could be some data type mismatch but getting the full error and screen shot of the job only can help us to dig further.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

Anonymous
Not applicable
Author

They are both actually strings.  I am trying to move a string to a string.  I have definitely narrowed it down to this translation, because if I just put in default text in that field to test it, it runs the job with no errors.   I have confirmed, both fields in the input and the output are strings. Strange behavior.