July 30, 2023

tSetEnv – Docs for ESB 7.x

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
needed for the job. name
: Enter the syntax for the
new variable.

value: Enter a parameter value
according to the context.

append: Select this check box to
add the new variable at the end.

Advanced settings

tStatCatcher Statistics

Select this check box to gather the processing metadata at the Job
level as well as at each component level.

Global Variables

Global Variables

ERROR_MESSAGE: the error message generated by the
component when an error occurs. This is an After variable and it returns a string. This
variable functions only if the Die on error check box is
cleared, if the component has this check box.

A Flow variable functions during the execution of a component while an After variable
functions after the execution of the component.

To fill up a field or expression with a variable, press Ctrl +
Space
to access the variable list and choose the variable to use from it.

For further information about variables, see
Talend Studio

User Guide.

Usage

Usage rule

tSetEnv can be used as a start or
an intermediate component.

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

  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.

    tSetEnv_1.png

  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.
tSetEnv_2.png

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.

    tSetEnv_3.png

  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).

    tSetEnv_4.png

  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.


Document get from Talend https://help.talend.com
Thank you for watching.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x