In some workflows, the solution requires handing over a variable from one object to another. This article helps you understand the general concept of sharing variables in IWS.
...
How to share variable from one task to another?
Let's assume you have two objects on the worksheet, object A and object B.
To make a variable pass from object A to object B, you should place this variable into object A's OutParams and then code for Object B to allow it to receive the variable and process it.
Object A's OutParams are set in its Properties box.
The variable should be placed into the box without any specific symbols, as shown here:
...
Panel |
---|
/53CAparam_TASK_my_translator_var_name/53CA |
Let's take a closer look at this name format:
/53CA is the IWS code for the ":" (colon) character, so this expression stands for:
Panel |
---|
:param_TASK_my_translator_var_name: |
Warning | ||
---|---|---|
| ||
Don't forget to replace ":" with /53CA when you paste the code into IWS. |
Example of use: Condition to Execute.have a look at the following example with two translators: shared_var_test_1 and shared_var_test_2. We want to share a variable (called variableA) from one translator to another.
Step-by-step instruction to do that:
Double-click first translator to open its worksheet and drop the Variable shape from the left panel ToolBox in CONTROL OBJECTS group:
By default, the variable is named as var. To set another name, click to the shape, and change the property Name in the left panel.
In our example we want to rename it to variableA.
To set a value for the variable, click the shape and put the value to the fx input on top of the workspace using quotes.
Update the default variable varTaskParams
Expand | ||||
---|---|---|---|---|
| ||||
Drop the Code shape from left panel in ADVANCED group and set value of the Code shape as
If you need to share more variables you can add them to the Code shape using syntax variable_name;variable_value!. For example, if we have another variable count to share, the Code shape value is set like this:
|
Expand | |||||||
---|---|---|---|---|---|---|---|
| |||||||
Drop the Call Include shape from the left panel in ADVANCED group to the workspace and click the edit… link on the shape The include file will open for edit: Paste the following code into the editor
You can change the code between the two green lines <!-- Code which you can change starts here --> and <!-- Code which you can change ends here --> to add shared variables. In our case: If you need to share more variables, you can add them using syntax variable_name;variable_value!. For example, to share another variable count the code between green lines will be as follows
Now you can save and close editor tab |
Return to the workflow and select the first translator. In the OutParams propertyin the right panel set the name of the variable to share (variableA in our case)
If you add several variables, use comma separator in OutParams property, for example, variableA,variable1,variable2,…
Now we can call variable variableA like this EXPR#:param_variableA:
Click to the second translator and in the property CustomCMParams set the name of the variable in first column, which you will use in the translator. It is not necessary to use the original name variableA in first column.
In the second column you must use
EXPR#:param_TASK_[name_of_task]_[original_name_of_shared_parameter]:
construction. In our case it will be
EXPR#:param_TASK_shared_var_test_1_variableA:
EXPR#:param_TASK_ is a required prefix. [name_of_task] is the name of the task where shared variable was created (shared_var_test_1 in our example). And variableA is the original name of the shared variable.
Double click second translator. Here you can use :param_it_is_shared_var: construction.
param_ is a required prefix, then goes the name which you set in CustomCMParams property earlier.
Workspace of the second translator.
We drop a STATUS shape to check the value of the variable.
Status after workflow launch