One Star

set the global context variable in job

Hi,
Is there a way to have a job to set the global context variable? I was able to set it only in the context of the job but I need it to apply for all jobs referencing it at runtime.
thanks
5 REPLIES
Community Manager

Re: set the global context variable in job

Hello
I was able to set it only in the context of the job but I need it to apply for all jobs referencing it at runtime.

In the first job, output the result(value of global variable) to a file.
At the beginning of other jobs, using tContextLoad to load the value of context from the file.
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: set the global context variable in job

Thanks Shong. I also tried using globalMap by setting key/value in the job and tried retrieve it in another, but evidently it is not 'global' across jobs.
Community Manager

Re: set the global context variable in job

Hello
I also tried using globalMap by setting key/value in the job and tried retrieve it in another, but evidently it is not 'global' across jobs.

The globalMap variable is only avaiable within the current job, not for other jobs. As I said before, if you want to use a variable in other jobs at the runtime, you should output the value of variable to a file first, and then load the value at the begining of other jobs. eg:
tFixedFlowInpu---tFileOutputDelimited(output a new vlaue of variable to a file, for example, the result of file looks like: key;newValue)
|
onsubJobOK
|
tRunJob_1
|
onsubJobOK
|
tRunJob_2
in the begining of tRunJob_1 and tRunJob2, load the value of context vars
tFileInputDelimited---tContextLoad
|
other subJobs
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: set the global context variable in job

Thanks, it works well. Although I have more variables I need to write out. I ended up doing multiple tfixflowinput flows in order to populate the key/value columns properly. Is there a more elegant way to go about it? Some iteration of sorts?

Re: set the global context variable in job

you can also use the tBufferOutput components to pass values back out of subjobs