|
| 1 | +--- |
| 2 | +title: Set Pipeline Return Value |
| 3 | +titleSuffix: Azure Data Factory & Azure Synapse |
| 4 | +description: Learn how to use the Set Variable activity to send information from child pipeline to main pipeline |
| 5 | +ms.service: data-factory |
| 6 | +ms.subservice: orchestration |
| 7 | +ms.custom: synapse |
| 8 | +ms.topic: conceptual |
| 9 | +ms.date: 2/12/2022 |
| 10 | +author: chez-charlie |
| 11 | +ms.author: chez |
| 12 | +ms.reviewer: jburchel |
| 13 | +--- |
| 14 | + |
| 15 | +# Set Pipeline Return Value in Azure Data Factory and Azure Synapse Analytics |
| 16 | +[!INCLUDE[appliesto-adf-asa-md](includes/appliesto-adf-asa-md.md)] |
| 17 | + |
| 18 | +In the calling pipeline-child pipeline paradigm, you can use the [Set Variable activity](control-flow-set-variable-activity.md) to return values from the child pipeline to the calling pipeline. In the following scenario, we have a child pipeline through [Execute Pipeline Activity](control-flow-execute-pipeline-activity.md). And we want to __retrieve information from the child pipeline__, to then be used in the calling pipeline. |
| 19 | + |
| 20 | +:::image type="content" source="media/pipeline-return-value/pipeline-return-value-00-paradigm.png" alt-text="Screenshot with ExecutePipeline Activity."::: |
| 21 | + |
| 22 | +Introduce pipeline return value, a dictionary of key value pairs, that allows communications between child pipelines and parent pipeline. |
| 23 | + |
| 24 | +## Prerequisite - Calling a Child Pipeline |
| 25 | + |
| 26 | +The prerequisite of the use case, is that you've an [Execute Pipeline Activity](control-flow-execute-pipeline-activity.md), calling a child pipeline. It's important that we enabled _Wait on Completion_ for the activity |
| 27 | + |
| 28 | +:::image type="content" source="media/pipeline-return-value/pipeline-return-value-01-execute-pipeline-setting.png" alt-text="Screenshot setting ExecutePipeline Activity to wait for completion."::: |
| 29 | + |
| 30 | + |
| 31 | +## Configure Pipeline Return Value in Child Pipeline |
| 32 | + |
| 33 | +We've expanded the [Set Variable activity](control-flow-set-variable-activity.md) to include system variables _Pipeline Return Value_. You don't need to define them at pipeline level (as opposed to any other variables you use in the pipeline). |
| 34 | + |
| 35 | +1. Search for _Set Variable_ in the pipeline Activities pane, and drag a Set Variable activity to the pipeline canvas. |
| 36 | +1. Select the Set Variable activity on the canvas if it isn't already selected, and then its **Variables** tab, to edit its details. |
| 37 | +1. Choose _Pipeline return value_ for variable type. |
| 38 | +1. Select _New_ to add a new key value pair. |
| 39 | +1. You can add reasonable number of key value pairs, bounded by size limit of returning json. |
| 40 | + |
| 41 | +:::image type="content" source="media/pipeline-return-value/pipeline-return-value-02-child-pipeline.png" alt-text="Screenshot shows the ui for pipeline return value."::: |
| 42 | + |
| 43 | +There are a few options for value types, including |
| 44 | + |
| 45 | +Type Name | Description |
| 46 | +-------- | ----------- |
| 47 | +String | The most straight forward of all. It expects a string value. |
| 48 | +Expression | It allows you to reference output from previous activities. |
| 49 | +Array | It expects an array of _string values_. Press "enter" key to separate values in the array |
| 50 | +Boolean | True or False |
| 51 | +Null | Signal place holder status; the value is constant _null_ |
| 52 | +Int | It expects a numerical value of integer type |
| 53 | +Float | It expects a numerical value of float type |
| 54 | +Object | __Warning__ complicated use cases only. It allows you to embed a list of key value pairs type for the value |
| 55 | + |
| 56 | +Value of object type is defined as follows: |
| 57 | + |
| 58 | +``` json |
| 59 | +[{"key": "myKey1", "value": {"type": "String", "content": "hello world"}}, |
| 60 | + {"key": "myKey2", "value": {"type": "String", "content": "hi"}} |
| 61 | +] |
| 62 | +``` |
| 63 | + |
| 64 | +## Retrieving Value in Calling Pipeline |
| 65 | + |
| 66 | +The pipeline return value of the child pipeline becomes the activity output of the Execute Pipeline Activity. You can retrieve the information with _@activity('Execute Pipeline1').output.pipelineReturnValue.keyName_. The use case is limitless. For instance, you may use |
| 67 | +* An _int_ value from child pipeline to define the wait period for a [wait activity](control-flow-wait-activity.md) |
| 68 | +* A _sting_ value to define the URL for the [Web activity](control-flow-web-activity.md) |
| 69 | +* An _expression_ value payload for a [script activity](transform-data-using-script.md) for logging purposes. |
| 70 | + |
| 71 | +:::image type="content" source="media/pipeline-return-value/pipeline-return-value-03-calling-pipeline.png" alt-text="Screenshot shows the calling pipeline."::: |
| 72 | + |
| 73 | +There are two noticeable call outs in referencing the pipeline return values. |
| 74 | + |
| 75 | +1. With _Object_ type, you may further expand into the nested json object, such as _@activity('Execute Pipeline1').output.pipelineReturnValue.keyName.nextLevelKey_ |
| 76 | +2. With _Array_ type, you can specify the index in the list, with _@activity('Execute Pipeline1').output.pipelineReturnValue.keyName[0]_. The number is zero indexed, meaning that it starts with 0. |
| 77 | + |
| 78 | +> [!NOTE] |
| 79 | +> Please make sure that the _keyName_ you are referencing exists in your child pipeline. ADF expression builder can _not_ confirm the referential check for you. |
| 80 | +> Pipeline will fail if the key referenced is missing in the payload |
| 81 | +
|
| 82 | +## Special Considerations |
| 83 | + |
| 84 | +You may have multiple Set Pipeline Return value activities in a pipeline. However, please ensure that only one gets to run in a pipeline. |
| 85 | + |
| 86 | +:::image type="content" source="media/pipeline-return-value/pipeline-return-value-04-multiple.png" alt-text="Screenshot with Pipeline Return Value and Branching."::: |
| 87 | + |
| 88 | +To avoid missing key situation in the calling pipeline, described above, we encourage you to have the same list of keys for all branches in child pipeline. Consider using _null_ types for keys that don't have values, in a specific branch. |
| 89 | + |
| 90 | +## Next steps |
| 91 | +Learn about another related control flow activity: |
| 92 | +- [Set Variable Activity](control-flow-set-variable-activity.md) |
| 93 | +- [Append Variable Activity](control-flow-append-variable-activity.md) |
| 94 | + |
0 commit comments