{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":4044,"path":"build-workflows/workflow-studio/create-data-gathering-action-dynamic-choice.md","title":"Create a data gathering action for a dynamic choice","bundle":null,"doc_type":null,"release":"australia","body":"\n# Create a data gathering action for a dynamic choice\n\nCreate a data gathering action to generate a list of choice options for a dynamic choice input.\n\n## Before you begin\n\n-   Role required: action\\_designer or admin\n-   Create credentials and connections for your REST endpoint\n\n**Note:** Dynamic inputs are not available in the base system. To use dynamic inputs in Workflow Studio, you must [Request an Integration Hub plugin](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/integrate-applications/request-integrationhub.md).\n\n## Procedure\n\n1.  Navigate to **All** &gt; **Process Automation** &gt; **Flow Designer**.\n\n2.  Select **Create New** &gt; **Action**.\n\n3.  In the **Name** field, enter a name for your action, choose the proper **Application** scope, and then select **Submit**.\n\n4.  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.\n\n    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](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/rest-request-action-designer.md) and [REST in IntegrationHub](https://developer.servicenow.com/app.do#!/training/article/app_store_learnv2_rest_paris_rest_in_integrationhub/app_store_learnv2_rest_paris_rest_in_integrationhub_objectives?v=paris).\n\n5.  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.\n\n    1.  From Input Variables, select **Create Variable**.\n\n        This input variable stores the REST response body.\n\n        For example for the input variable Name, enter `payload`.\n\n    2.  For the input variable Value, select the data pill for the REST step's **Response Body** output.\n\n    3.  In Script, enter a script to create a JSON output from the input variable.\n\n        Your script needs to do these tasks.\n\n        -   **Parse the input variable as JSON**\n\n            You can use the [JSON - Global](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/server-api-reference/c_JSONAPI.md) API to transform the input variable from a string to a JSON object.\n\n        -   **Create a new JSON object formatted for a dynamic choice**\n\n            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 a `label` and a `name` property 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.\n\n            For example, this JSON object defines an array with three choice list options.\n\n            ```\n            {\n                data: [\n                    {\n                        label: \"Choice Option 1\",\n                        name: \"choice_option_1\"\n                        \n                    }, \n                    {\n                        label: \"Choice Option 2\",\n                        name: \"choice_option_2\"\n                    }, \n                    {\t\n                        label: \"Choice Option 3\",\n                        name: \"choice_option_3\"\n                    }\n                ]\n            }\n            ```\n\n            **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.\n\n        -   **Set the outputs object**\n\n            Set the outputs object to return your dynamic choice JSON object.\n\n    4.  From Output Variables, select **Create Variable**.\n\n        This output variable stores the choice list options your script creates.\n\n    5.  For the output variable type, select **JSON**.\n\n        The script output variable type must be JSON.\n\n6.  In the Action Outline, select **Outputs**\n\n    1.  Select Create Output.\n\n    2.  Set the output label and name `output`.\n\n    3.  Set the output type to **JSON**.\n\n        **Note:** The action can have multiple outputs, but there can only be one of type JSON.\n\n    4.  Select **Exit Edit Mode**.\n\n    5.  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.\n\n7.  Select **Save** and [test the action](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/test-action.md).\n\n    The runtime value for `output` must be a JSON object that has a `data` property and an array of choice list options.\n\n    \\[Omitted image \"example-output-dga-dynamic-choice.png\"\\] Alt text: Example output from testing action\n\n8.  Select **Publish** to make the action available to other flows and actions within the same application scope.\n\n\n## Result\n\nYou 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.\n\n**Parent Topic:**[Dynamic inputs](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/dynamic-inputs.md)\n\n**Related topics**  \n\n\n[Get started with dynamic inputs]()\n\n[Create a data gathering action for a dynamic template]()\n\n[Create a data gathering action for a dynamic inputs type input]()\n\n[Dynamic input configuration options]()\n\n"}}