One Star tle
One Star

Using JAVA Code for Default Context

Hi,
I use a parameter for my Job(it's OK) , but for the default value, I would like to have a today date (which is JAVA code) , and so the user doesn't enter every time. How can I do to indicate (syntaxe) for the Default value that is the JAVA code.
Thanks in advance for your help.
tle
4 REPLIES
One Star

Re: Using JAVA Code for Default Context

This isn't exactly what you're asking for but if you're working with databases you can always ask the database for the current time. Adda DBInput component and you're ready. At least that's the way I do that so far.
One Star

Re: Using JAVA Code for Default Context

You can also avoid using a db query :
try with a single line tJava component at the beginning of your job, such as :
context.setProperty("yourDateContextParameter", routines.TalendDate.getDate("yyyyMMdd"));
Hope this helps
One Star tle
One Star

Re: Using JAVA Code for Default Context

Hi,
Thanks a lot for all help, but using db query is not exactly that I want. I have try with context.setProperty.
I can use both contexts of the Job and tJava component.
It's OK, but the context.setProperty don't accept integer value and I have set string value for my date .Do you know another way to have integer value ? . It's my screenshot.
tle
One Star

Re: Using JAVA Code for Default Context

Using java and context values, I admit you only can use String values, since 'contextValue' is a 'Properties' type variable
So why not set your "datecontrol" context parameter as an int ?
Then you can read it with : Integer.parseInt(((String)context.getProperty("datecontrol"))).intValue()
And you still can write it as a String.