Five Stars

or expression in combination with "?" operator

Hello everybody,

I'm new to Talend and I have a question. Maybe simple...but I don't get it.

This is my expression:

 

(null != row1.Premium_Group1?

(row1.Premium_Group.contains("Group (group administration/ external audit)")?
"x":" ") :

" ")

 

First he checks for a null value, if not, he checks for the expression "Group (group ad...", if the expression exists "x" if not " ". Works so far.

But for the next Ouput field I have to check  two input field. So the expression should look like:

 

(null != row1.Premium_Group1?

(row1.Premium_Group1.contains("Group (group administration/ external audit)")?
"x":" ") :

" ")

 

or ( || )

 

(null != row1.Premium_Group2?

(row1.Premium_Group2.contains("Group (/group administration/ external audit)")?
"x":" ") :

" ")

 

What kind of expression I have to use instead of "||" . I hope someone can help me Smiley Happy

 

PS: later one I have to check for 5 input fields. So the solution should be scalable.

 

Cheers,

Christian

1 ACCEPTED SOLUTION

Accepted Solutions
Five Stars

Re: or expression in combination with "?" operator

I've got a solution. More luck than skill and dirty ... but it works for all fields.

 

(null != row1.Premium_Group1?

(row1.Premium_Group1.contains("Group (group administration/ external audit)")?
"x":" ") :

" ")

 

+

 

(null != row1.Premium_Group2?

(row1.Premium_Group2.contains("Group (/group administration/ external audit)")?
"x":" ") :

" ")

 

+

 

....

 

5 REPLIES
Eleven Stars

Re: or expression in combination with "?" operator

How are you wanting to use your OR here? You are not outputting a boolean, you are outputting a String. So if you want to use the OR you need to provide the logic behind it.

 

By the way, you can use OR as || in these conditions

 

 

Rilhia Solutions
Five Stars

Re: or expression in combination with "?" operator

"the or("||") comment isn't a part of my expression. I just wanted to describe my concern. My data source is a questionnaire. I get the data via web API (Json). I have a checkbox question with 6 answers. The Ouput is Json looks like that:

"At group level, how was the premium allocated? Please check ": [                      //Question
"Group ... (IMS/group administration/ external audit)",                                        //Answer1
"Products....( storage)",                                                                                  //Answer2 etc.
"Basic ....and sanitation"
]
The description of an answer (i.e. "Group ... (IMS/group administration/ external audit)") stands for the fact, that the user signed the checkbox. Otherwise the answer isn't part of the Json. In that case the user signed 3 of them.
Each answer (in total 6) receive its own column in the output table. Now I have to check, If someone choosed i.e. "Group ... (IMS/group administration/ external audit)". For the first column I can use

(null != row1.Premium_Group1?
(row1.Premium_Group1.contains("Group (group administration/ external audit)")?
"x":" ") :
" ")

That's enough. But when someone in the questionnaire doesn't choose Answer1 but Answer2, Answer2 will be on "Position 1" inside the Json String of the question. So in my second ouput column (to check answer2) I have to add the second part to the expression, to check for position 1 and position 2 inside the Json String
I'm using tExtractJsonFields and the mapping looks like this:

 

Mapping_json.jpg

So all in all I think my solution should work. But I don't know how to use 

(null != row1.Premium_Group1?

(row1.Premium_Group1.contains("Group (group administration/ external audit)")?
"x":" ") :

" ")

several times in one expression with different kinds of input fields (positions in the Json). 

My post was now unfortunately longer than expected. I hope that makes the whole thing more clear.

 

Cheers,

Christian

Eleven Stars

Re: or expression in combination with "?" operator

I see. You can maybe use tMap variables to help with this. I have written a tutorial which shows how to move your data dynamically between columns. It is not really what you are doing here, but the methodology might give you a few clues. Take a look here: https://www.rilhia.com/tutorials/dynamic-column-order

Rilhia Solutions
Five Stars

Re: or expression in combination with "?" operator

I will check. Thanks.

Five Stars

Re: or expression in combination with "?" operator

I've got a solution. More luck than skill and dirty ... but it works for all fields.

 

(null != row1.Premium_Group1?

(row1.Premium_Group1.contains("Group (group administration/ external audit)")?
"x":" ") :

" ")

 

+

 

(null != row1.Premium_Group2?

(row1.Premium_Group2.contains("Group (/group administration/ external audit)")?
"x":" ") :

" ")

 

+

 

....