Unable to set context variable in tJava

Five Stars

Unable to set context variable in tJava

I'm trying to set context variable value when the default value is null.

but the code didn't work for me. I'm not sure whats missing in below statements:

 

 

if(context.lgc_bus_dt==null){
context.lgc_bus_dt=TalendDate.formatDate("yyyyMM",TalendDate.addDate(TalendDate.getCurrentDate(),-1,"MM"));};

System.out.println( "Context variable value is:"+context.lgc_bus_dt);

it returns Null though even when i'm setting the variable value when its null.


Accepted Solutions
Nine Stars

Re: Unable to set context variable in tJava

try the following if you are using lgc_bus_dt datatype is string.

 

if(context.lgc_bus_dt==null || context.lgc_bus_dt.equals("") ){
context.lgc_bus_dt=TalendDate.formatDate("yyyyMM",TalendDate.addDate(TalendDate.getCurrentDate(),-1,"MM"));}


System.out.println( "Context variable value is:"+context.lgc_bus_dt);

 

DateContext.PNG

Regards,

Veeru Boppudi

All Replies
Nine Stars

Re: Unable to set context variable in tJava

try the following if you are using lgc_bus_dt datatype is string.

 

if(context.lgc_bus_dt==null || context.lgc_bus_dt.equals("") ){
context.lgc_bus_dt=TalendDate.formatDate("yyyyMM",TalendDate.addDate(TalendDate.getCurrentDate(),-1,"MM"));}


System.out.println( "Context variable value is:"+context.lgc_bus_dt);

 

DateContext.PNG

Regards,

Veeru Boppudi
Five Stars

Re: Unable to set context variable in tJava

Thanks Veera. It worked like charm.

Tutorial

Introduction to Talend Open Studio for Data Integration.

Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.