Using custom action JSON output as an input in the workflow

  • Last update on September 22nd, 2023

When creating a new workflow, the output of a custom action can serve as an input for the subsequent action in the workflow. In such cases, the output in JSON format can be passed as an input for the next action using “Dynamic mapping”. This option becomes visible in the workflow once the custom action is incorporated.

Firstly, you need to create and submit a custom action that will produce output in JSON format. For instance, in the example below, a custom action was created to generate a random password, and it returns the result in JSON:

$password=

("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+-=|;':\,./<>?".ToCharArray() | sort {Get-Random})[1..16] -join''

$json= @"
{"RandomPassword":"$password"}
"@

return $json

After incorporating the custom action into the workflow, you can assign the JSON output property to a variable. This variable can then be used in subsequent steps of the workflow.

To accomplish this, simply click on the ellipsis button found on the top right corner of your screen and select “Set Dynamic Mapping”:

Next, choose “Add dynamic mapping”. This will present an option that lets you map the JSON output from the previous custom action as input for one of the subsequent actions.

From the “Actions” dropdown menu, select the name of the custom action you configured earlier. In the “Name” field, enter the name of the variable you wish to declare for your workflow. In the “Path name” field, enter “response[0].yourjsonproperty”. In our example, this would be “RandomPassword”.

Once you hit the “Save” button, the variable you've declared will show up as an Input variable. You can then select it for any input values in your workflow tasks.