Passing a value from the parent Job to the child Job is a common real world requirement. This article serves as a best practice guide.
This procedure was written with:
The following environment was used to create the suggested procedure.
This example reads data from a text file in a parent Job and passes fields from each row to the child Job. The data is used in the child Job.
id;name;scope 1;Shong;98 2;Ross;90 3;Tom;55 4;Patrick;99 5;Pedro;90
Create a Job called ParentJob. The Job design is as follows. (You will configure tRunJob in the configuration step).
Create a child Job. Call it ChildJob.
Drag and drop a tJava component from the Palette to the Job editor. In the tJava component, type in the following Java code:
String message="Hello "+context.name+", you get "+context.scope+" points in this exam!"; System.out.println(message);
Open the Contexts viewer, and define two context variables: name and scope, as follows:
Return to the parent Job, configure the tRunJob component as follows:
Execute the Job ParentJob. The following results will print to the console:
Starting job ParentJob at 11:38 12/12/2011. [statistics] connecting to socket on port 3768 [statistics] connected Hello Shong, you get 98 points in this exam! Hello Ross, you get 90 points in this exam! Hello Tom, you get 55 points in this exam! Hello Patrick, you get 99 points in this exam! Hello Pedro, you get 90 points in this exam! [statistics] disconnected Job ParentJob ended at 11:38 12/12/2011. [exit code=0]
The most important technical point is using the context variable, defined in the child Job, to pass a value from parent Job to child Job.