Five Stars

Problem in tMap (datarange & conditions)

Hello dear community,

 

As a new talend open studio user, I'm struggling on a job, looking for some help.I have a XML file that i get from tHttpRequest; then a main row to textractXMLfield to formatdata.

Problem is, I have a field returning " 2018-02-20T22:00+0200/2018-03-31T23:59+0200 " which is a data range where a discount_price is active.

I need to consider that in my formatting & only show the discount_price if the current date is between this range, so i splitted it (with tExtractDelimitedFields) and get an input for my tMap which looks :

 

tLogRow (input)                                   tMap (out)                             tLogRow

ID                                                            ID

date_begin                                           discount_price

date_end

discount_price

 

Date_begin & Date end looks like : "yyyy-MM-dd".

I would like my out of tMap with ID of products and discount_price shown only if current date is between date_begin & date_end, otherwise empty field.

 

So I tried something like this to begin as a condition on the out :

 

(TalendDate.compareDate(TalendDate.getCurrentDate(),TalendDate.parseDate("yyyy-MM-dd",row7.date1)) == 1 && TalendDate.compareDate(TalendDate.getCurrentDate(),TalendDate.parseDate("yyyy-MM-dd",row7.date4)) == -1)? row7.Discount_price : " "

 

But infortunately; after 6 rows, errors : Caused by: java.text.ParseException: Unparseable date: "". My 7th rows has an empty date,  I have no idea how to check this condition, neither rewrite price only if the data is between range.

If someone could unlock me, would be very (very) appreciable.

 

Regards

 

 

 

Tags (3)
1 ACCEPTED SOLUTION

Accepted Solutions
Eleven Stars

Re: Problem in tMap (datarange & conditions)

@daez,can you try the below expresion. since some in 7th row you were getting empty values,so thats why it is not able to convert.

 

row7.date1 != "" && row7.date4 != "" ?((TalendDate.compareDate(TalendDate.getCurrentDate(),TalendDate.parseDate("yyyy-MM-dd",row7.date1)) == 1 && TalendDate.compareDate(TalendDate.getCurrentDate(),TalendDate.parseDate("yyyy-MM-dd",row7.date4)) == -1)? row7.Discount_price : " "):" "

Manohar B
3 REPLIES
Eleven Stars

Re: Problem in tMap (datarange & conditions)

@daez,can you try the below expresion. since some in 7th row you were getting empty values,so thats why it is not able to convert.

 

row7.date1 != "" && row7.date4 != "" ?((TalendDate.compareDate(TalendDate.getCurrentDate(),TalendDate.parseDate("yyyy-MM-dd",row7.date1)) == 1 && TalendDate.compareDate(TalendDate.getCurrentDate(),TalendDate.parseDate("yyyy-MM-dd",row7.date4)) == -1)? row7.Discount_price : " "):" "

Manohar B
Seven Stars

Re: Problem in tMap (datarange & conditions)

You'll need an empty string  / null check when you parse those variables . I typically add a few temp vars to the tMap in the middle column to accomplish this. see my example below2018-05-03_8-47-14.png

 

 

 

Five Stars

Re: Problem in tMap (datarange & conditions)

@manodwhb Thank you so much. It works. I was working and forgot to instant check forum. I had issue on the first condition, checking if both were null. 

 

Thanks again, what a relief when you F6 and it works !