Talend : Passing values from Parent Job to Child Job

08 / Sep / 2015 by Geetika Chhabra 1 comments

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:

job1

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"

job 3

Create a Job B like as shown below:  (Job 2 is a tRunJob component which is calling the above Job)

job2

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.

final 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 !!

FOUND THIS USEFUL? SHARE IT

comments (1 “Talend : Passing values from Parent Job to Child Job”)

Leave a Reply to Abhi Cancel reply

Your email address will not be published. Required fields are marked *