Talend : Passing values from Parent Job to Child Job
In the previous post, I discussed automating content migration process using Talend. As the power of Talend lies with creating meaningful jobs, it solves a particular business problem. More often than not, one job has to talk to another job.
Use case:
While working on a migration project, I had a use case where I wanted to pass a value from a Parent Job to a Child Job.
Problem:
globalMap
is a useful way to pass values, but it can only be used to pass the values within same Job. For Instance, If I have a Job A
like below:
where tJava_1
is setting a key in globalMap
,
[java]globalMap.put("testVal","Test Value 1");[/java]
and tJava_2
is trying to retrieve its value.
[java]System.out.println("testVal in the same job is "+(String)globalMap.get("testVal"));[/java]
Its value can be retrieved from the components defined in the same Job but if we try to access those values outside this Job, we’ll get the null value.
Solution:
The problem can be resolved by utilizing the power of “Context Variables”. Create a Job 2
like as shown below and define a context variable "testValue"
Create a Job B
like as shown below: (Job 2
is a tRunJob
component which is calling the above Job)
Here tJava_1
is setting a key in globalMap
,
[java]globalMap.put("testVal","Test Value 1");[/java]
To access the above value in Job 2
, define this component’s properties as below. Note the “Context Param"
definition, this is how we can set the value in the context variable and retrieve it in the child job.
tJava_1
in Child Job can simply retrieve its value :
[java]System.out.println("testVal in the another job is "+context.testValue);[/java]
Hope it helps !!
Thank you , it is very helpful