tSetEnv
Adds variables temporarily to system environment during the execution of a
Job.
tSetEnv creates
variables and execute a Job script through communicating the information about the newly
created variables between subJobs. After job execution, the newly created variables are
deleted.
tSetEnv Standard properties
These properties are used to configure tSetEnv running in the Standard Job framework.
The Standard
tSetEnv component belongs to the System family.
The component in this framework is available in all Talend
products.
Basic settings
Parameters |
Click the plus button to add the variables
value: Enter a parameter value
append: Select this check box to |
Advanced settings
tStatCatcher Statistics |
Select this check box to gather the processing metadata at the Job |
Global Variables
Global Variables |
ERROR_MESSAGE: the error message generated by the A Flow variable functions during the execution of a component while an After variable To fill up a field or expression with a variable, press Ctrl + For further information about variables, see |
Usage
Usage rule |
tSetEnv can be used as a start or |
Modifying a variable during a Job execution
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
-
Create a first Job named parentJob:
right-click on the Job Design node of the
Repository, and choose Create a Job. - From the Palette, drop a tSetEnv component, two tMsgBox components, and one tRunJob component onto the design workspace.
-
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. -
Connect the first tMsgBox component to the
tRunJob with a OnSubjobOk link. -
Then connect the tRunJob component to the
second tMsgbox with a OnSubjobOk link. - Now create a child Job named ChildJob.
- From the Palette, drop a tSetEnv component onto the design workspace.
-
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.
-
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. -
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). -
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. -
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. -
Now double-click the tRunJob component to open the
child Job ChildJob. -
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. -
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). -
Save your Job, go back to parentJob, then
run the Job by pressing F6.
Run the Job
-
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.