You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/data-factory/control-flow-set-variable-activity.md
+40-13Lines changed: 40 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
---
2
2
title: Set Variable Activity
3
3
titleSuffix: Azure Data Factory & Azure Synapse
4
-
description: Learn how to use the Set Variable activity to set the value of an existing variable defined in an Azure Data Factory or Azure Synapse Analytics pipeline.
4
+
description: Learn how to use the Set Variable activity to set the value of an existing variable defined in an Azure Data Factory or Azure Synapse Analytics pipeline or to set a pipeline return value.
5
5
ms.service: data-factory
6
6
ms.subservice: orchestration
7
7
ms.custom: synapse
8
8
ms.topic: conceptual
9
-
ms.date: 10/24/2022
9
+
ms.date: 02/16/2023
10
10
author: chez-charlie
11
11
ms.author: chez
12
12
ms.reviewer: jburchel
@@ -15,19 +15,43 @@ ms.reviewer: jburchel
15
15
# Set Variable Activity in Azure Data Factory and Azure Synapse Analytics
Use the Set Variable activity to set the value of an existing variable of type String, Bool, or Array defined in a Data Factory or Synapse pipeline.
18
+
Use the Set Variable activity to set the value of an existing variable of type String, Bool, or Array defined in a Data Factory or Synapse pipeline or use the Set Variable activity to set a pipeline return value (preview).
19
19
20
-
## Create an Append Variable activity with UI
20
+
## Create a Set Variable activity with UI
21
21
22
22
To use a Set Variable activity in a pipeline, complete the following steps:
23
+
23
24
1. Select the background of the pipeline canvas and use the Variables tab to add a variable:
24
-
:::image type="content" source="media/control-flow-activities-common/add-pipeline-array-variable.png" alt-text="Screenshot shows an empty pipeline canvas with the variables tab selected having an array type variable named TestVariable.":::
25
+
26
+
:::image type="content" source="media/control-flow-activities-common/add-pipeline-array-variable.png" alt-text="Screenshot of an empty pipeline canvas with the Variables tab selected with an array type variable named TestVariable.":::
27
+
28
+
2. Search for _Set Variable_ in the pipeline Activities pane, and drag a Set Variable activity to the pipeline canvas.
29
+
30
+
3. Select the Set Variable activity on the canvas if it isn't already selected, and then click the **Settings** tab to edit its details.
31
+
32
+
4. Select the variable for the Name property.
33
+
34
+
5. Enter an expression to set the value for the variables. This expression can be a literal string expression, or any combination of dynamic [expressions, functions](control-flow-expression-language-functions.md), [system variables](control-flow-system-variables.md), or [outputs from other activities](how-to-expression-language-functions.md#examples-of-using-parameters-in-expressions).
35
+
36
+
:::image type="content" source="media/control-flow-set-variable-activity/set-variable-activity.png" alt-text="Screenshot of the UI for a Set variable activity.":::
37
+
38
+
## Setting a pipeline return value in the Set Variable activity with UI
39
+
40
+
The Set Variable activity now allows you to set a pipeline return value (preview). The pipeline return value is a system variable that allows you to customize a value that can be consumed by a parent pipeline and used downstream in your pipeline.
41
+
42
+
To set a pipeline return value, complete the following steps:
25
43
26
44
1. Search for _Set Variable_ in the pipeline Activities pane, and drag a Set Variable activity to the pipeline canvas.
27
-
1. Select the Set Variable activity on the canvas if it is not already selected, and its **Variables** tab, to edit its details.
28
-
1. Select the variable for the Name property.
29
-
1. Enter an expression to set the value for the variables. This expression can be a literal string expression, or any combination of dynamic [expressions, functions](control-flow-expression-language-functions.md), [system variables](control-flow-system-variables.md), or [outputs from other activities](how-to-expression-language-functions.md#examples-of-using-parameters-in-expressions).
30
-
:::image type="content" source="media/control-flow-set-variable-activity/set-variable-activity.png" alt-text="Screenshot shows the ui for a set variable activity.":::
45
+
46
+
2. Select the Set Variable activity on the canvas if it isn't already selected, and then click the **Settings** tab to edit its details.
47
+
48
+
3. Select **Pipeline return value (preview)** for your **Variable type**.
49
+
50
+
4. Enter a **Name** for your variable and select the **Type** from the drop-down menu.
51
+
52
+
5. Enter an expression to set the value for the pipeline return value. This expression can be a literal string expression, or any combination of dynamic [expressions, functions](control-flow-expression-language-functions.md), [system variables](control-flow-system-variables.md), or [outputs from other activities](how-to-expression-language-functions.md#examples-of-using-parameters-in-expressions).
53
+
54
+
:::image type="content" source="media/control-flow-set-variable-activity/set-pipeline-return-value.png" alt-text="Screenshot of the UI for setting a pipeline return value.":::
description | Text describing what the activity does | no
38
62
type | Must be set to **SetVariable** | yes
39
-
value | String literal or expression object value that the variable is assigned to | yes
40
63
variableName | Name of the variable that is set by this activity | yes
64
+
value | String literal or expression object value that the variable is assigned to | yes
65
+
41
66
42
67
## Incrementing a variable
43
68
44
-
A common scenario involving variables is using a variable as an iterator within an until or foreach activity. In a set variable activity, you cannot reference the variable being set in the `value` field. To work around this limitation, set a temporary variable and then create a second set variable activity. The second set variable activity sets the value of the iterator to the temporary variable.
69
+
A common scenario involving variables is to use a variable as an iterator within an **Until** or **ForEach** activity. In a **Set variable** activity, you can't reference the variable being set in the `value` field. To work around this limitation, set a temporary variable and then create a second **Set variable** activity. The second **Set variable** activity sets the value of the iterator to the temporary variable.
@@ -99,10 +126,10 @@ Below is an example of this pattern:
99
126
}
100
127
```
101
128
102
-
Variables are currently scoped at the pipeline level. This means that they are not thread safe and can cause unexpected and undesired behavior if they are accessed from within a parallel iteration activity such as a foreach loop, especially when the value is also being modified within that foreach activity.
129
+
Variables are currently scoped at the pipeline level. This means that they're not thread safe and can cause unexpected and undesired behavior if they are accessed from within a parallel iteration activity such as a ForEach loop, especially when the value is also being modified within that foreach activity.
130
+
103
131
104
132
## Next steps
105
133
Learn about another related control flow activity:
0 commit comments