Dynamic context values

One Star

Dynamic context values

Hello
I am trying to have my context provide a dynamic value (a date in my case).
So in my context, I have an OPEN_DATE key, with the following value: TalendDate.formatDate("yyyy-MM-dd",TalendDate.addDate(TalendDate.getCurrentDate(),-1,"dd"))
But the property's value in my job is literally that string, and not yesterday's date.
I would like to do such a thing to keep a hand on changing that date without having to open up and modify my job.
Any options?
Thanks.
Fred
Community Manager

Re: Dynamic context values

Dear Fred
If you want a Date type, don't format it to String, use the following expression should be ok:
TalendDate.addDate(TalendDate.getCurrentDate(),-1,"dd")
If you want a String type, just did as you done:
TalendDate.formatDate("yyyy-MM-dd",TalendDate.addDate(TalendDate.getCurrentDate(),-1,"dd"))
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Dynamic context values

Hi Shong
This is not the problem. Having a String is what I want.
Question is, I have a global context set for my jobs. In this case, I don't want to hardcode a date. So in the context value for key OPEN_DATE, I put a talend expression instead of a literal.
But when that context value is processed, the actual talend expression is not interpolated and I end up with the actual talend expression literal in my job.
Am I making sense?
Thank you.
fred
One Star

Re: Dynamic context values

Here is what my context would look like.
Community Manager

Re: Dynamic context values

Hi
Where do you type in the expression?
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Dynamic context values

In a text file, that get loading as implicit context for the project.
One Star

Re: Dynamic context values

Or in the actual job context. Neither actually works.
Community Manager

Re: Dynamic context values

Hi
Set the context value on tJava at the beginning of job, for example:
tJava
|
onsujobok
|
do other processing
on tJava:
context.varName=TalendDate.formatDate("yyyy-MM-dd",TalendDate.addDate(TalendDate.getCurrentDate(),-1,"dd"));
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Dynamic context values

My point is to have that outside the actual job, so that I could change the date at will, without opening the job (in case of manual rerun for example).
So I am guessing this is not possible or? Feature request?
Community Manager

Re: Dynamic context values

Hi
Yes, it is possible, you can set the context value when you execute the job script out of studio. see
http://www.talendforge.org/forum/viewtopic.php?id=1615
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Dynamic context values

But to take this example, can you then call the job with:
--context_param open_date=TalendDate.formatDate("yyyy-MM-dd",TalendDate.addDate(TalendDate.getCurrentDate(),-1,"dd"))
and expect your open_date value to be 20111025 ? Because, when I do so, I get TalendDate.formatDate("yyyy-MM-dd",TalendDate.addDate(TalendDate.getCurrentDate(),-1,"dd")) in my open_date variable.
I am using the Pro version btw.
Community Manager

Re: Dynamic context values

Hi
I am not sure I understand you well, in this example, you can only set a value with String or Integer/int type, for example:
--context_param open_date='20111025'
In the job, you will parse and convert it to other type if needed.
Can you upload some screenshot of jobs or export the job and send it to me? So that I could understand what you really want to do?
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Dynamic context values

Exactly, this is the point. So it doesn't seem to be possible. I guess it'd be good to be able to put a function call in there, and not just an integer or a string, for the sake of flexibility. What do you think?
In the day to day operation, I don't want to have to pass a hardcoded value to my context, such as '20111024', but rather have this value dynamically passed in as a function call. The date obviously changes everyday.
However, sometimes, I would like to launch the job with a hardcoded value, without having to touch the job itself, because I have to "replay" the job for a specific date.
So if I do it within the job, whenever I want to launch it for a specific date, I have to go into the job, put the hardcoded value instead of the Talend function, and change it back afterwards.
If we could pass a function as a context value, I would not have to open the job and I'd have the best of both world.
Community Manager

Re: Dynamic context values

Hi
A function can't be interpreted out of the job, it is always considered as String, however, you can define the function in the job and you only need to pass the parameters to the job when you execute the job each time.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Dynamic context values

Right.
I opened a feature request Smiley Wink
Thanks
fred