Skip to main content

Set Variable Activity

Overview​

The Set Variable (set_variable) Activity in the Package Editor allows you to pass data back from the child package to a parent package. By defining output variables and assigning values within the child package, package developers can expose execution results, status information, or other data that can be referenced by the parent package after the child package completes execution.

The Set Variable Activity can be located by simply searching for "Set Variable" in the list of activities in the package editor:

The following example demonstrates how the Set Variable activity can be used within a nested automation to pass values from a child package back to the parent package.

Parent Package


# Pia Automation Package
conditions:
- name: 'client_filter'
optMode: 'OptOut'
category: 'Hello World'

- name: 'chat'
option_button: 'Set Variable Parent'
option_text: 'Text which is displayed in the Pia Chatbot'
option_category: 'Pia Chatbot Category'

steps:
- task: start_package
alias: 'child'
inputs:
mode: 'inline'
package_id: '1aa7b2f4-994d-4039-96f8-1c131ded8a5b'

- task: inline_powershell
inputs:
result: =child.result_data
count: =child.processed_count
script: |
Write-Host "Child result: $result"
Write-Host "Items processed: $count"

Child Package


# Pia Automation Package
conditions:
- name: 'client_filter'
optMode: 'OptOut'
category: 'Hello World'

- name: 'chat'
option_button: 'Set variable child'
option_text: 'Text which is displayed in the Pia Chatbot'
option_category: 'Pia Chatbot Category'

steps:
- task: set_variable
inputs:
key: 'result_data'
value: 'Processing completed successfully'

- task: set_variable
inputs:
key: 'processed_count'
value: '42'

In this example, the Set Variable activity is used within the child package to define and expose two variables:

  • result_data
  • processed_count

When the parent package invokes the child package using the start_package activity, any variables created using Set Variable are automatically returned to the parent package. These values can then be accessed using the child package alias (child) and referenced as:


=child.result_data
=child.processed_count

Activity Behavior​

The Set Variable activity enables a child package to return data to its parent package. It works in conjunction with the Start Package activity.

When a parent package launches a child package using the Start Package activity, the child package is executed independently. During its execution, the child package can use one or more Set Variable activities to define output values. Once the child package completes, these output values are passed back to the parent package and made available as the output of the corresponding Start Package activity.

This activity can be used in all types of package executions. This includes packages which have been initiated via Pia Tech Assist or via Ticketing System Event.

Input Properties​

Use properties to modify the behavior of the activity.

Property Name: key
Property Required: Yes
Property Description: This is the name of the output variable to create. This variable can be referenced by parent packages using the activity alias (e.g., =child_alias.variable_name).

Property Name: value
Property Required: Yes
Property Description: This is the value to assign to the output variable. This can be a literal value, expression, or reference to other variables.

Property Name: description
Property Required: No
Property Description: This is the description of the output variable to be created. This variable can be displayed on the 'start_package' activity annotation.

Output Properties​

The activity creates output variable based on the input provided and does not have additional output properties.