Create a data gathering action for a dynamic choice
On this page
Create a data gathering action for a dynamic choice
Create a data gathering action to generate a list of choice options for a dynamic choice input.
Before you begin
-
Role required: action_designer or admin
-
Create credentials and connections for your REST endpoint
Note: Dynamic inputs are not available in the base system. To use dynamic inputs in Workflow Studio, you must Request an Integration Hub plugin.
Procedure
-
Navigate to All > Process Automation > Flow Designer.
-
Select Create New > Action.
-
In the Name field, enter a name for your action, choose the proper Application scope, and then select Submit.
-
In the Action Outline, select the add a new step icon ([Omitted image "add-new-step-icon.png"] Alt text: Add a new step icon) under Inputs and select the REST step.
Configure your REST step to get data from the proper Base URL and Resource Path with any applicable Query Parameters for the HTTP Method
GET. For more information on using the REST step in Integration Hub, see REST step and REST in IntegrationHub. -
In the Action Outline under the REST step, select the add a new step icon ([Omitted image "add-new-step-icon.png"] Alt text: Add a new step icon) and select the Script step.
-
From Input Variables, select Create Variable.
This input variable stores the REST response body.
For example for the input variable Name, enter
payload. -
For the input variable Value, select the data pill for the REST step's Response Body output.
-
In Script, enter a script to create a JSON output from the input variable.
Your script needs to do these tasks.
-
Parse the input variable as JSON
You can use the JSON - Global API to transform the input variable from a string to a JSON object.
-
Create a new JSON object formatted for a dynamic choice
You must know the data structure of the REST Response to map response values to choice list options. Your script must create a dynamic choice JSON object that has a property named
data. The value of the data property must be an array of choice list options. Each choice list option must have alabeland anameproperty set to string values. The label property determines how the option appears in the choice list. The name property determines how the option is stored and referred to in the system.For example, this JSON object defines an array with three choice list options.
{ data: [ { label: "Choice Option 1", name: "choice_option_1" }, { label: "Choice Option 2", name: "choice_option_2" }, { label: "Choice Option 3", name: "choice_option_3" } ] }Note: A dynamic choice input can only display up to 5000 choice list options. A JSON object that returns more than 5000 choice list options will be truncated when it is rendered.
-
Set the outputs object
Set the outputs object to return your dynamic choice JSON object.
-
-
From Output Variables, select Create Variable.
This output variable stores the choice list options your script creates.
-
For the output variable type, select JSON.
The script output variable type must be JSON.
-
-
In the Action Outline, select Outputs
-
Select Create Output.
-
Set the output label and name
output. -
Set the output type to JSON.
Note: The action can have multiple outputs, but there can only be one of type JSON.
-
Select Exit Edit Mode.
-
Next to the Value field, select the data pill picker ([Omitted image "data_pill_picker.png"] Alt text: Data pill picker) and then select Script step output variable you created to store choice list options.
-
-
Select Save and test the action.
The runtime value for
outputmust be a JSON object that has adataproperty and an array of choice list options.[Omitted image "example-output-dga-dynamic-choice.png"] Alt text: Example output from testing action
-
Select Publish to make the action available to other flows and actions within the same application scope.
Result
You can now use your data gathering action to populate the options that appear for a dynamic choice input in a parent action.[Omitted image “create-data-gathering-action-dynamic-choice-result.png”] Alt text: Use your data gathering action to populate options for a dynamic choice.
Parent Topic:Dynamic inputs
Related topics
{Get started with dynamic inputs}[]
{Create a data gathering action for a dynamic template}[]
{Create a data gathering action for a dynamic inputs type input}[]
{Dynamic input configuration options}[]
Keep exploring.
Find another answer, or bring this documentation into your own tools.