Scenario: Modifying a variable during a Job execution - 6.1

Talend Components Reference Guide

EnrichVersion
6.1
EnrichProdName
Talend Big Data
Talend Big Data Platform
Talend Data Fabric
Talend Data Integration
Talend Data Management Platform
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for Big Data
Talend Open Studio for Data Integration
Talend Open Studio for Data Quality
Talend Open Studio for ESB
Talend Open Studio for MDM
Talend Real-Time Big Data Platform
task
Data Governance
Data Quality and Preparation
Design and Development
EnrichPlatform
Talend Studio

The following scenario is made of two Jobs parent and child. With the tSetEnv component, you can transfer and modify in a child Job a value created in a parent Job. As part of this Job, the tMsgBox components allow you to display, for information purposes only, that a variable is properly set, via an info-box.

To modify the value of the parent Job by using a variable set in the tSetEnv component, do as described in the following sections:

Drop and link components

  1. Create a first Job named parentJob: right-click on the Job Design node of the Repository, and choose Create a Job.

  2. From the Palette, drop a tSetEnv component, two tMsgBox components, and one tRunJob component onto the design workspace.

  3. Connect the tSetEnv component to a first tMsgBox component with a OnSubjobOk link : right-click on the start component, select Trigger, then OnSubjobOk. Then click on the end component you want to connect.

  4. Connect the first tMsgBox component to the tRunJob with a OnSubjobOk link.

  5. Then connect the tRunJob component to the second tMsgbox with a OnSubjobOk link.

  6. Now create a child Job named ChildJob.

  7. From the Palette, drop a tSetEnv component onto the design workspace.

  8. Connect the tSetEnv component to the tMsgBox with a OnSubjobOk link: right-click on the start component, select Trigger, then OnSubjobOk. Then click on the end component you want to connect.

Set the components

In this example, the value set in the parent Job is transferred to the child Job. There, it is modified and adopts the value of the child Job, and then transferred to the parent Job again.

  1. In parentJob, select the tSetEnv component and click the Component tab. Add a variable row by clicking the [+] button to set the initial value of the variable. Type Variable_1 in the Name field, and Parent job value in the Value field.

  2. Select the first tMsgBox component, and click the Component tab. In the Message field, type the message displayed in the info-box which confirms that your variable has properly been taken into account. For example: "Parent:"+System.getProperty("Variable_1") displays the variable set in the tSetEnv component (here Parent job value).

  3. Select the second tMsgBox component, and click the Component tab. In the Message field, type the "Parent:"+System.getProperty("Variable_1") line again. It makes the variable set in the child Job appear.

  4. Select the tRunJob component and click the Component tab. In the Job field, type the name of your child Job, here ChildJob. This will run the child Job when you run the parent Job.

  5. Now double-click the tRunJob component to open the child Job ChildJob.

  6. Select the tSetEnv component, and click the Component tab. Add a variable row by clicking the [+] button to set the initial value of the variable. Type Variable_1 in the Name field, and Child job value in the Value field.

  7. Select the tMsgBox component and click the Component tab. In the Message field, type the message displayed in the info-box which confirms that your variable has properly been taken into account. For example: "Son:"+System.getProperty("Variable_1") displays the variable set in the tSetEnv component (here Child job value).

  8. Save your Job, go back to parentJob, then run the Job by pressing F6.

Run the Job

Three info-boxes are displayed one after the other:

  • Parent: Parent job value: parent Job's value is Parent job value.

  • Child: Child job value: Child Job's value is Child job value.

  • Parent: Child job value: parent Job's value was modified by the variable set in the tSetEnv of the child Job, then transferred again to the parent Job. parent Job's value is now the one set in the child Job.