[resolved] Date is not supported in the if else condition

Highlighted
One Star

[resolved] Date is not supported in the if else condition

Hi,
I have input excel(row1) with dates in the format "mm/dd/yyyy" and i have mapped the date in tmap expression builder using the if else condition. In the output the the calculated double value should be the result.
Input excel Format:
Date              Condition
08/09/2015          Y
10/09/2015          N
In tmap expression builder, i have given the condition as below,
row1.Condition.equals("Y")? ((TalendDate.diffDate(row1.Date, TalendDate.getCurrentDate(), "dd") < 365 ) ? 0.20 : 0.5):0.0
In the above if condition, the row1.Date is not taking the value from the input excel sheet.
Getting the below error as,
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 

Exception in component tMap_1
java.lang.NullPointerException
My requirement is to find the difference between the date from the input excel and current date and if its less than 365 days then reture value 0.20 otherwise 0.5. If the condition not satisfies then should return value 0.
Please help me to correct this one. Or suggest me anyother alternative way to call the date from input excel.

Accepted Solutions
Highlighted
Community Manager

Re: [resolved] Date is not supported in the if else condition

Hi
Read Date column from excel file with Date type, and set its pattern as "MM/dd/yyyy" rather than "mm/dd/yyyy" on the schema. 
Exception in component tMap_1
java.lang.NullPointerException

Please check if there exist null value in Condition column, if so, you need to handle the null value before using the expression like:
row1.Condition.equals("Y")


Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business

View solution in original post


All Replies
Highlighted
Community Manager

Re: [resolved] Date is not supported in the if else condition

Hi
Read Date column from excel file with Date type, and set its pattern as "MM/dd/yyyy" rather than "mm/dd/yyyy" on the schema. 
Exception in component tMap_1
java.lang.NullPointerException

Please check if there exist null value in Condition column, if so, you need to handle the null value before using the expression like:
row1.Condition.equals("Y")


Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business

View solution in original post

Highlighted
One Star

Re: [resolved] Date is not supported in the if else condition

This works fine. Thank you

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog