Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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
Labels (2)
14 Replies
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

Here is what my context would look like.
Anonymous
Not applicable
Author

Hi
Where do you type in the expression?
Best regards
Shong
Anonymous
Not applicable
Author

In a text file, that get loading as implicit context for the project.
Anonymous
Not applicable
Author

Or in the actual job context. Neither actually works.
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

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?
Anonymous
Not applicable
Author

Hi
Yes, it is possible, you can set the context value when you execute the job script out of studio. see
https://community.talend.com/t5/Design-and-Development/resolved-Passing-variable-context-value-from-...
Best regards
Shong