{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":4219,"path":"build-workflows/workflow-studio/getting-started-dynamic-input.md","title":"Get started with dynamic inputs","bundle":null,"doc_type":null,"release":"australia","body":"\n# Get started with dynamic inputs\n\nCreate a sample action that illustrates using all available types of dynamic inputs in a flow.\n\n## Before you begin\n\nRole required: action\\_designer or admin\n\n## Procedure\n\n1.  [Create credential and connection records for your instance](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/getting-started-dynamic-input.md).\n\n    This connection &amp; credential alias will provide the base URL and user account needed to configure the REST steps of your data gathering actions.\n\n2.  [Create a data gathering action to get table names](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/getting-started-dynamic-input.md).\n\n    This data gathering action will provide JSON data for dynamic choice inputs.\n\n3.  [Create a data gathering action to get field names](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/getting-started-dynamic-input.md).\n\n    This data gathering action provides JSON data for dynamic template inputs.\n\n4.  [Create a data gathering action to add dynamic inputs](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/getting-started-dynamic-input.md).\n\n    This data gathering action provides JSON data to create arbitrary dynamic inputs.\n\n5.  [Create a custom action to test dynamic inputs](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/getting-started-dynamic-input.md).\n\n    This custom action illustrates different types of dynamic inputs.\n\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[Create a data gathering action for a dynamic choice]()\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## Create credential and connection records for your instance\n\nCreate the aliases, connections, and credentials needed to connect to your local instance.\n\n### Before you begin\n\nRole required: admin\n\n### Procedure\n\n1.  Navigate to **All** &gt; **Connections &amp; Credentials** &gt; **Credentials**.\n\n2.  Select **New**, select **Basic Auth Credentials**, and enter these field values.\n\n    1.  For **Name**, enter `Local Admin`.\n\n    2.  For **User name**, enter a user account with access to Flow Designer and the REST API.\n\n        For example, enter `admin`.\n\n    3.  For **Password**, enter the account password.\n\n3.  Select **Submit** to create the credential record.\n\n4.  Navigate to **All** &gt; **Connections &amp; Credentials** &gt; **Connection &amp; Credential Aliases**.\n\n5.  Select **New** and enter these fields values.\n\n    1.  For **Name**, enter Local Instance.\n\n    2.  Accept the default value of HTTP for the **Connection type**.\n\n    3.  Select **Submit** to create the Connection &amp; Credential Alias record.\n\n6.  Select the alias you created.\n\n    For example, select **Local Instance**.\n\n7.  From the Connections related list, select **New**, and enter these field values.\n\n    1.  For **Name**, enter `My Instance`.\n\n    2.  For Credential, select the basic authentication credential record you created.\n\n        For example, select the **Local Admin** credential.\n\n    3.  For Connection URL, enter the base URL for your instance including the forward slash at the end.\n\n        Include the URL prefix https:// and add a slash character at the end of the URL.\n\n        For example, `https://example.service-now.com/`.\n\n    4.  Select **Submit** to create the HTTP\\(s\\) Connection record.\n\n\n### Result\n\nYou can use the Local Instance alias to connect to your local instance when configuring REST steps.\n\n## Create a data gathering action to get table names\n\nCreate a custom data gathering action to fetch a list of table names from the Table API.\n\n### Before you begin\n\nRole required: action\\_designer or admin\n\n### About this task\n\nThis data gathering action consists of these elements.\n\n-   A REST step to gather table names from the REST [Table API](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/c_TableAPI.md)\n-   A script step to construct a JSON payload from the REST step's Response Body\n-   An action output variable named `output` to store table name and value pairs as a JSON document\n\nThis custom action uses a REST API call to duplicate the functionality of the ServiceNow core [Look Up Record action](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/lookup-record-flow-designer.md) and [Look Up Records action](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/lookup-records-flow-designer.md). Typically, you do not need to create custom actions to perform basic record operations. This action illustrates working with the REST and Script steps to gather table data for dynamic inputs.\n\n### Procedure\n\n1.  Navigate to **All** &gt; **Process Automation** &gt; **Workflow Studio**.\n\n2.  On the homepage, select **Actions**.\n\n3.  Select **Create new** &gt; **Action**.\n\n    1.  On the Action properties screen, in the **Action name** field, enter `Data Gathering Action for Tables`.\n\n    2.  For **Application**, select Global.\n\n    3.  Select **Submit**.\n\n    \\[Omitted image \"create-dga-tables-01.png\"\\] Alt text: Example action properties created from step 2\n\n4.  In the Action Outline under the Inputs section, select the add a new step icon \\(\\[Omitted image \"add-new-step-icon.png\"\\] Alt text: Add a new step icon\\).\n\n5.  From the **Integrations** section, select the **REST** step, and enter these field values.\n\n<table id=\"table_pvd_ftf_mjb\"><thead><tr><th>\n\nInput\n\n</th><th>\n\nValue\n\n</th></tr></thead><tbody><tr><td>\n\nConnection\n\n</td><td>\n\nLeave **Use Connection Alias** selected.\n\n</td></tr><tr><td>\n\nConnection Alias\n\n</td><td>\n\nSelect the alias you created earlier, or select the Create new record icon \\(\\[Omitted image \"create-new-record-icon.png\"\\] Alt text: Create new record icon\\) to [Create an HTTP\\(s\\) connection](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-security/create-https-connection.md).**Note:** The **Credential** for the HTTP\\(s\\) connection must use [Basic authentication credentials](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-security/r_BasicAuthCredentialsForm.md). Additionally, the **Connection URL** must be the base URL for your instance, including the forward slash at the end. For more information on connections and credentials, see [Getting started with connections](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-security/connection-information.md) and [Getting started with credentials](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-security/credentials-getting-started.md).\n\n</td></tr><tr><td>\n\nBuild Request\n\n</td><td>\n\nLeave the **Manually** option selected\n\n</td></tr><tr><td>\n\nResource Path\n\n</td><td>\n\nEnter `api/now/doc/table/schema`\n\n</td></tr><tr><td>\n\nHTTP Method\n\n</td><td>\n\nEnter `GET`\n\n</td></tr></tbody>\n</table>    \\[Omitted image \"create-dga-tables-02-rest-step.png\"\\] Alt text: Example REST step configuration from steps 3 and 4\n\n6.  In the Action Outline under your REST step, select the Add a new step icon \\(\\[Omitted image \"add-new-step-icon.png\"\\] Alt text: New step icon\\), and select the **Script** step.\n\n    1.  In the Input Variables section, select **Create Variable**.\n\n    2.  In the **Name** field, enter `payload`.\n\n    3.  Next to the **Value** field, select the data pill picker \\(\\[Omitted image \"data\\_pill\\_picker.png\"\\] Alt text: Data pill picker\\) and select **REST Step** &gt; **Response Body**.\n\n    4.  In the **Script** field, enter the following code.\n\n        ```\n        \n        (function execute(inputs, outputs) {\n          var payload = JSON.parse(inputs.payload);\n          var tables = payload.result // Get the value of the result array\n            .filter(function(table) { return table.value.indexOf('_') < 0; }) // Filter the tables we want\n            .map(function(table) { \n              return { label: table.label, name: table.value }; // Set values for label and name \n          });\n          outputs.tables = { data: tables }; // Final, properly formatted output\n        })(inputs, outputs);\n        ```\n\n        The REST API returns a JSON-formatted string that describes each table with the image, reference, rawLabel, selected, label, missing, used, and value properties. The label and value properties provide the values needed by for a dynamic choice. A dynamic choice requires that each choice option have a label and a name. This script maps the value property to a name property.\n\n    5.  In the Output Variables section, select **Create Variable**.\n\n    6.  In the **Label** and **Name** fields, enter `tables`.\n\n    7.  In the **Type** field, select `JSON`.\n\n    \\[Omitted image \"create-dga-tables-03-script-step.png\"\\] Alt text: Example Script step configuration from step 5\n\n7.  In the Action Outline, select **Outputs**.\n\n    1.  Select **Create Output**.\n\n    2.  In the **Label** and **Name** fields, enter `output`.\n\n    3.  In the **Type** field, select `JSON`.\n\n    4.  Select **Exit Edit Mode**.\n\n    5.  Next to the **Value**, select the data pill picker \\(\\[Omitted image \"data\\_pill\\_picker.png\"\\] Alt text: Data pill picker\\) and select **Script step** &gt; **tables**.\n\n    \\[Omitted image \"create-dga-tables-04-outputs.png\"\\] Alt text: Example action output configuration from step 6\n\n8.  In the Action header, select **Save** and then select **Test** to [test the action](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/test-action.md).\n\n    1.  Select **Run Test**.\n\n    2.  View the action's execution details.\n\n        Your data gathering action runs successfully if the runtime value for `tables` is a complex object containing an array of key-value pairs for `label` and `name` as shown in the following abbreviated example.\n\n        ```\n        {\n          \"data\": [\n            {\n              \"name\": \"evaluation\",\n              \"label\": \"A/B Testing Evaluation\"\n            },\n            {\n              \"name\": \"sla\",\n              \"label\": \"Agreement\"\n            },\n            {\n              \"name\": \"announcement\",\n              \"label\": \"Announcement\"\n            },\n            {\n              \"name\": \"cmdb\",\n              \"label\": \"Base Configuration Item\"\n            },\n            {\n              \"name\": \"checklist\",\n              \"label\": \"Checklist\"\n            },\n            {\n              \"name\": \"collaborator\",\n              \"label\": \"Collaborator\"\n            },\n            {\n              \"name\": \"conflict\",\n              \"label\": \"Conflict\"\n            },\n            {\n              \"name\": \"clone\",\n              \"label\": \"Database Clone\"\n            },\n            {\n              \"name\": \"dsl\",\n              \"label\": \"DML\"\n            },\n            {\n              \"name\": \"global\",\n              \"label\": \"Global\"\n            },\n            {\n              \"name\": \"goal\",\n              \"label\": \"Goal\"\n            },\n            {\n              \"name\": \"incident\",\n              \"label\": \"Incident\"\n            },\n            {\n              \"name\": \"interaction\",\n              \"label\": \"Interaction\"\n            },\n            {\n              \"name\": \"map\",\n              \"label\": \"Map\"\n            },\n            {\n              \"name\": \"ola\",\n              \"label\": \"OLA\"\n            },\n            {\n              \"name\": \"problem\",\n              \"label\": \"Problem\"\n            },\n            {\n              \"name\": \"question\",\n              \"label\": \"Question\"\n            },\n            {\n              \"name\": \"reminder\",\n              \"label\": \"Reminder\"\n            },\n            {\n              \"name\": \"instance\",\n              \"label\": \"ServiceNow Instance\"\n            },\n            {\n              \"name\": \"label\",\n              \"label\": \"Tag\"\n            },\n            {\n              \"name\": \"task\",\n              \"label\": \"Task\"\n            },\n            {\n              \"name\": \"taxonomy\",\n              \"label\": \"Taxonomy\"\n            },\n            {\n              \"name\": \"ticket\",\n              \"label\": \"Ticket\"\n            },\n            {\n              \"name\": \"topic\",\n              \"label\": \"Topic\"\n            },\n            {\n              \"name\": \"expert\",\n              \"label\": \"Wizard\"\n            }\n          ]\n        }\n        ```\n\n    \\[Omitted image \"create-dga-tables-06-execution-details.png\"\\] Alt text: Example action execution details from step 7\n\n9.  In the Action header, select **Publish** to make this action available to other flows and actions within the Global scope.\n\n\n## Create a data gathering action to get field names\n\nCreate a data gathering action to get a list of fields from a table.\n\n### Before you begin\n\nRole required: action\\_designer or admin\n\n### About this task\n\nThis data gathering action consists of these elements.\n\n-   A REST step to gather fields from the REST [Table API](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/c_TableAPI.md)\n-   A script step to construct a JSON payload from the REST step's Response Body\n-   An action output variable named `output` to store field name and value pairs as a JSON document\n\nThis custom action uses a REST API call to duplicate the functionality of the ServiceNow core [Look Up Record action](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/lookup-record-flow-designer.md) and [Look Up Records action](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/lookup-records-flow-designer.md). Typically, you do not need to create custom actions to perform basic record operations. This action illustrates working with the REST and Script steps to gather field data for dynamic inputs.\n\n### Procedure\n\n1.  Navigate to **All** &gt; **Process Automation** &gt; **Workflow Studio**.\n\n2.  On the homepage, select **Actions**.\n\n3.  Select **Create new** &gt; **Action**.\n\n    1.  On the Action properties screen, in the **Action name** field, enter `Data Gathering Action for Fields`.\n\n    2.  For **Application**, select Global.\n\n    3.  Select **Submit**.\n\n    \\[Omitted image \"create-dga-fields-01-action-properties.png\"\\] Alt text: Example action properties from step 2\n\n4.  From the Action Outline, select **Inputs**.\n\n    1.  In the Action Input header, select **Create Input**.\n\n    2.  In the **Label** and **Name** fields, enter `Table`.\n\n    3.  In the **Type** field, select **String**.\n\n    4.  Toggle the **Mandatory** slider so that it is active.\n\n    5.  Select the Toggle Advanced Inputs icon to show the advanced inputs.\n\n    6.  For **Default value**, enter `incident`.\n\n    \\[Omitted image \"create-dga-fields-02-inputs.png\"\\] Alt text: Example input configuration from step 3\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: New step icon\\).\n\n6.  From the **Integrations** section, select the **Script** step, and enter these field values.\n\n    1.  In the Input Variables section, select **Create Variable**.\n\n    2.  In the **Name** field, enter `table`.\n\n    3.  Next to the **Value**, select the data pill picker \\(\\[Omitted image \"data\\_pill\\_picker.png\"\\] Alt text: Data pill picker\\) and select **Action** &gt; **Table**.\n\n    4.  In the **Script** field, enter the following code.\n\n        ```\n        \n        (function execute(inputs, outputs) {\n            if(!inputs.table || inputs.table === \"-- None --\") { // check for empty or no table \n              outputs.table = \"incident\"; // set default table to incident\n            } else {\n              outputs.table = inputs.table; // use input value provided\n            }\n        })(inputs, outputs);\n        ```\n\n        This script ensures that the REST step always has a table name.\n\n    5.  In the Output Variables section, select **Create Variable**.\n\n    6.  In the **Label** and **Name** fields, enter `table`.\n\n    7.  In the **Type** field, select **String**.\n\n    \\[Omitted image \"create-dga-fields-02-script-input-default-value.png\"\\] Alt text: Example Script step configuration from step 5\n\n7.  In the Action Outline under the Inputs section, select the Add a new step icon \\(\\[Omitted image \"add-new-step-icon.png\"\\] Alt text: New step icon\\).\n\n8.  From the **Integrations** section, select the **REST** step, and enter these field values.\n\n<table id=\"table_gym_n5f_mjb\"><thead><tr><th>\n\nInput\n\n</th><th>\n\nValue\n\n</th></tr></thead><tbody><tr><td>\n\nConnection\n\n</td><td>\n\nLeave **Use Connection Alias** selected.\n\n</td></tr><tr><td>\n\nConnection Alias\n\n</td><td>\n\nSelect the alias you created earlier, or select the Create new record icon \\(\\[Omitted image \"create-new-record-icon.png\"\\] Alt text: Create new record icon\\) to [Create an HTTP\\(s\\) connection](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-security/create-https-connection.md).**Note:** The **Credential** for the HTTP\\(s\\) connection must use [Basic authentication credentials](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-security/r_BasicAuthCredentialsForm.md). Additionally, the **Connection URL** must be the base URL for your instance, including the forward slash at the end. For more information on connections and credentials, see [Getting started with connections](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-security/connection-information.md) and [Getting started with credentials](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-security/credentials-getting-started.md).\n\n</td></tr><tr><td>\n\nBuild Request\n\n</td><td>\n\nLeave **Manually** selected.\n\n</td></tr><tr><td>\n\nResource Path\n\n</td><td>\n\nEnter `api/now/table/` and then select the data pill picker \\(\\[Omitted image \"data\\_pill\\_picker.png\"\\] Alt text: Data pill picker\\). Select **Script step** &gt; **Table**.\n\n</td></tr><tr><td>\n\nHTTP Method\n\n</td><td>\n\nEnter `GET`\n\n</td></tr><tr><td>\n\nQuery Parameters\n\n</td><td>\n\nAdd this query parameter to make the REST API only return one record.-   **Name**: sysparm\\_limit\n-   **Value**: 1\n\n\n</td></tr></tbody>\n</table>    \\[Omitted image \"create-dga-fields-03-rest-step.png\"\\] Alt text: Example REST step configuration from step 7\n\n9.  In the Action Outline under the REST step, select the Add a new step icon \\(\\[Omitted image \"add-new-step-icon.png\"\\] Alt text: New step icon\\).\n\n10. From the **Integrations** section, select the **Script** step, and enter these field values.\n\n    1.  In the Input Variables section, select **Create Variable**.\n\n    2.  In the **Name** field, enter `payload`.\n\n    3.  Next to the **Value**, select the data pill picker \\(\\[Omitted image \"data\\_pill\\_picker.png\"\\] Alt text: Data pill picker\\) and select **REST Step** &gt; **Response Body**.\n\n    4.  In the **Script** field, enter the following code.\n\n        ```\n        \n        (function execute(inputs, outputs) {\n          var payload = JSON.parse(inputs.payload);\n          var fields = Object.keys(payload.result[0]) // Get first record of array\n            .map(function(property) {\n              return {\n                label: property.charAt(0).toUpperCase() + property.slice(1).replace(/_/g, ' '), // Create label from field name\n                name: property, // Set name to field name\n                value: '' // Set value to empty so that dynamic template can set value\n              };\n            });\n          outputs.fields = { data: fields }; // final properly formatted output\n        })(inputs, outputs);\n        ```\n\n        The REST API returns a JSON-formatted string that describes each field as a set of name value pairs where the name is the field name and value is the field value. A dynamic template only needs the field name and label. The field value must be blank so that it can be set by the template value. The label property is calculated from the field name by capitalizing the first letter and replacing underscore characters with spaces.\n\n    5.  In the Output Variables section, select **Create Variable**.\n\n    6.  In the **Label** and **Name** fields, enter `fields`.\n\n    7.  In the **Type** field, select **JSON**.\n\n    \\[Omitted image \"create-dga-fields-04-script-step.png\"\\] Alt text: Example Script step configuration from step 9\n\n11. In the Action Outline, select **Outputs**.\n\n    1.  On the Action Output header, select **Create Output**.\n\n    2.  In the **Label** and **Name** fields, enter `output`.\n\n    3.  In the **Type** field, select **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** &gt; **fields**.\n\n    \\[Omitted image \"create-dga-fields-05-outputs.png\"\\] Alt text: Example output configuration from step 8\n\n12. In the Action header, select **Save** and then select **Test** to [test the action](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/test-action.md).\n\n    1.  On the Test Action screen, in the **Table** field, enter `incident`.\n\n    2.  Select **Run Test**.\n\n    3.  View the action's execution details.\n\n        Your data gathering action runs successfully if the runtime value for `output` is a complex object containing an array of key-value pairs for `label`, `name`, and `value` as shown in the following abbreviated example.\n\n        ```\n        {\n            \"data\": [\n              {\n                \"name\": \"parent\",\n                \"label\": \"Parent\",\n                \"value\": \"\"\n              },\n              {\n                \"name\": \"made_sla\",\n                \"label\": \"Made sla\",\n                \"value\": \"\"\n              },\n              {\n                \"name\": \"caused_by\",\n                \"label\": \"Caused by\",\n                \"value\": \"\"\n              },\n              {\n                \"name\": \"watch_list\",\n                \"label\": \"Watch list\",\n                \"value\": \"\"\n              },\n              {\n                \"name\": \"upon_reject\",\n                \"label\": \"Upon reject\",\n                \"value\": \"\"\n              },\n              {\n                \"name\": \"sys_updated_on\",\n                \"label\": \"Sys updated on\",\n                \"value\": \"\"\n              },\n              {\n                \"name\": \"...\",\n                \"label\": \"...\",\n                \"value\": \"\"\n              },\n              {\n                \"name\": \"category\",\n                \"label\": \"Category\",\n                \"value\": \"\"\n              }\n            ]\n          }\n        ```\n\n    \\[Omitted image \"create-dga-fields-07-execution-details.png\"\\] Alt text: Example action execution details from step 9\n\n13. In the Action header, click **Publish** to make this action available to other actions within the Global scope.\n\n\n## Create a data gathering action to add dynamic inputs\n\nCreate a data gathering action to add a reference type dynamic input.\n\n### Before you begin\n\nRole required: action\\_designer or admin\n\n### About this task\n\nThis data gathering action includes these elements.\n\n-   An action input variable to store a table name\n-   A script step to construct two dynamic inputs as a JSON object\n-   An action output variable named `output` to store the dynamic inputs\n\nThis custom action uses a reference type input to duplicate the functionality of the ServiceNow core [Look Up Record action](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/lookup-record-flow-designer.md) and [Look Up Records action](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/lookup-records-flow-designer.md). Generally, you don’t need to create custom actions to perform basic record operations. This action illustrates working with the Script steps to gather field data for dynamic inputs.\n\n### Procedure\n\n1.  Navigate to **All** &gt; **Process Automation** &gt; **Workflow Studio**.\n\n2.  On the homepage, select **Actions**.\n\n3.  Select **Create new** &gt; **Action**.\n\n    1.  On the Action properties screen, in the **Action name** field, enter `Data Gathering Action for Dynamic Inputs`.\n\n    2.  For **Application**, select Global.\n\n    3.  Select **Submit**.\n\n    \\[Omitted image \"create-dga-dynamic-01-action-properties.png\"\\] Alt text: Example action properties from step 2\n\n4.  From the Action Outline, select **Inputs**.\n\n    1.  In the Action Input header, select **Create Input**.\n\n    2.  In the **Label** and **Name** fields, enter `Table`.\n\n    3.  In the **Type** field, select **String**.\n\n    4.  Select the Toggle Advanced Inputs icon \\(\\[Omitted image \"icon-toggle-advanced-input.png\"\\] Alt text: Toggle advanced input icon\\).\n\n    5.  In the **Default value** field, enter `sys_user`.\n\n    \\[Omitted image \"create-dga-dynamic-02-inputs.png\"\\] Alt text: Example action input configuration from step 3\n\n5.  In the Action Outline under Inputs, select the Add a new step icon \\(\\[Omitted image \"add-new-step-icon.png\"\\] Alt text: New step icon\\).\n\n6.  From the **Integrations** section, select the **Script** step, and enter these field values.\n\n    1.  In the Input Variables section, select **Create Variable**.\n\n    2.  In the **Name** field, enter `table`.\n\n    3.  Next to the **Value**, select the data pill picker \\(\\[Omitted image \"data\\_pill\\_picker.png\"\\] Alt text: Data pill picker\\) and select **Inputs** &gt; **Table**.\n\n    4.  In the **Script** field, enter the following code.\n\n        ```\n        \n        (function execute(inputs, outputs) { \n            // Define JSON for desired dynamic input type\n            outputs.data = { \n                data: [{\n                  label: 'Reference type input',\n                  name: 'referencetype',\n                  reference: inputs.table,\n                  type: 'reference',\n                }]\n              }\n          })(inputs, outputs);\n        ```\n\n        Each type of dynamic input has its own JSON structure. A reference field dynamic input needs these properties.\n\n        -   **label**\n\n            The text to display next to the input. For example, Reference field input.\n\n        -   **name**\n\n            The internal name of the dynamic input used to identify it and to store values. For example, referencetype.\n\n        -   **reference**\n\n            The target table name of the reference field. For example, sys\\_user. In this script, the table name is a variable.\n\n        -   **type**\n\n            The data type of the dynamic input. For example, reference. The type property determines how Workflow Studio displays the input and what other properties are required to configure it.\n\n    5.  In the Output Variables section, select **Create Variable**.\n\n    6.  In the **Label** and **Name** fields, enter `data`.\n\n    7.  In the **Type** field, select **JSON**.\n\n    \\[Omitted image \"create-dga-dynamic-03-script-step.png\"\\] Alt text: Example script step configuration from steps 4 through 5\n\n7.  In the Action Outline, select **Outputs**.\n\n    1.  On the Action Output header, select **Create Output**.\n\n    2.  In the **Label** and **Name** fields, enter `output`.\n\n    3.  In the **Type** field, select **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** &gt; **data**.\n\n    \\[Omitted image \"create-dga-dynamic-04-outputs.png\"\\] Alt text: Example output configuration from step 6\n\n8.  In the Action header, select **Save** and then select **Test** to [test the action](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/test-action.md).\n\n    1.  Select **Run Test**.\n\n    2.  View the action's execution details.\n\n        If your data gathering action runs successfully, then the runtime value for `output` is a JSON string as shown in the following example.\n\n        ```\n        {\n          \"data\": [\n            {\n              \"reference\": \"sys_user\",\n              \"name\": \"referencetype\",\n              \"label\": \"Reference type input\",\n              \"type\": \"reference\"\n            }\n          ]\n        }\n        ```\n\n    \\[Omitted image \"create-dga-dynamic-06-execution-details.png\"\\] Alt text: Example action execution details from step 7\n\n9.  In the Action header, select **Publish** to make this action available to other actions within the Global scope.\n\n\n## Create a custom action to test dynamic inputs\n\nCreate a custom action to test dynamic inputs.\n\n### Before you begin\n\nRole required: action\\_designer or admin\n\n### About this task\n\nThis helper action duplicates the functionality of the [Create Record step](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/create-record-action-designer.md) to illustrate gathering data from a REST step. Generally, you use dynamic inputs for integrations to third-party systems and data.\n\nThis custom action includes these elements.\n\n-   An input of type Dynamic Choice to select a table\n-   An input of type Dynamic Template to select and set field values\n-   A script step to create a record from the [GlideRecord - Global](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/api-reference/server-api-reference/c_GlideRecordAPI.md)\n-   An action output variable named `output` to store the sys\\_id of the record created\n\n### Procedure\n\n1.  Navigate to **All** &gt; **Process Automation** &gt; **Workflow Studio**.\n\n2.  On the homepage, select **Actions**.\n\n3.  Select **Create new** &gt; **Action**.\n\n    1.  On the Action properties screen, in the **Action name** field, enter `Create Record from Dynamic Inputs`.\n\n    2.  For **Application**, select Global.\n\n    3.  Select **Submit**.\n\n    \\[Omitted image \"create-custom-action-01-action-properties.png\"\\] Alt text: Example action properties configuration from step 2\n\n4.  In the Action Outline, select **Inputs**.\n\n    1.  Select **Create Input**.\n\n    2.  In the **Label** and **Name** fields, enter `Table`.\n\n    3.  In the **Type** field, select **Dynamic Choice**.\n\n    4.  Turn on the **Mandatory** toggle switch.\n\n    5.  In **Default value**, enter `incident`.\n\n    6.  Accept the default value for **Choice**.\n\n    7.  Under Dynamic Options for the **Action** field, select **Data Gathering Action for Tables**.\n\n    8.  Select **Create Input** to create another action input.\n\n    9.  In the **Label** and **Name** fields, enter `Fields`.\n\n    10. In the **Type** field, select **Dynamic Template**.\n\n    11. Turn on the **Mandatory** toggle switch.\n\n    12. Under Dynamic Options in the **Action** field, select **Data Gathering Action for Fields**.\n\n    13. Next to the **Table** field, turn on the **Depends-On Another Input** toggle switch.\n\n    14. In the **Table** field, select the **Table** input.\n\n    15. Select **Create Input** to create another action input.\n\n    16. In the **Label** and **Name** fields, enter `Dynamic Input`.\n\n    17. In the **Type** field, select **Dynamic Inputs**.\n\n    18. Under Dynamic Options in the **Action** field, select **Data Gathering Action for Dynamic Inputs**.\n\n    19. Leave the **Table** field blank to use the default value of sys\\_user provided by the data gathering action.\n\n    \\[Omitted image \"create-custom-action-02-inputs.png\"\\] Alt text: example inputs configuration from step 3\n\n5.  In the Action Outline under the Inputs section, select the Add a new step icon \\(\\[Omitted image \"add-new-step-icon.png\"\\] Alt text: New step icon\\).\n\n6.  From the **Integrations** section, select the **Script** step, and enter these field values.\n\n    1.  In the Input Variables section, select **Create Variable**.\n\n    2.  In the **Name** field, enter `table`.\n\n    3.  Next to the **Value** field, select the data pill picker \\(\\[Omitted image \"data\\_pill\\_picker.png\"\\] Alt text: Data pill picker\\) and select **Inputs** &gt; **Table**.\n\n    4.  Select **Create Variable** to create another input variable.\n\n    5.  In the **Name** field, enter `fields`.\n\n    6.  Next to the **Value** field, select the data pill picker \\(\\[Omitted image \"data\\_pill\\_picker.png\"\\] Alt text: Data pill picker\\) and select **Inputs** &gt; **Fields**.\n\n    7.  Select **Create Variable** to create another input variable.\n\n    8.  In the **Name** field, enter `payload`.\n\n    9.  Next to the **Value** field, select the data pill picker \\(\\[Omitted image \"data\\_pill\\_picker.png\"\\] Alt text: Data pill picker\\) and select **Inputs** &gt; **Dynamic Input**.\n\n    10. In the **Script** field, enter the following code.\n\n        ```\n        \n        (function execute(inputs, outputs) {\n            var payload = inputs.payload.referencetype; // match name from data gathering action\n            var obj = JSON.parse(payload);\n            var user = obj.value;\n            var gr = new GlideRecord(inputs.table); // dynamic choice input\n            gr.applyEncodedQuery(inputs.fields); // dynamic template input\n            gr.applyEncodedQuery(\"caller_id=\" + user); // dynamic inputs reference field\n            gr.insert();\n            outputs.record = gr;\n            })(inputs, outputs);\n        ```\n\n    11. In the Output Variables section, select **Create Variable**.\n\n    12. In the **Label** and **Name** fields, enter `record`.\n\n    13. In the **Type** field, select **Document ID**.\n\n    \\[Omitted image \"create-custom-action-03-script-step.png\"\\] Alt text: Example Script step configuration from steps 4 through 5\n\n7.  In the Action Outline, select **Outputs**.\n\n    1.  On the Action Output header, select **Create Output**.\n\n    2.  In the **Label** and **Name** fields, enter `Record Created`.\n\n    3.  In the **Type** field, select **Document ID**.\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** &gt; **record**.\n\n    \\[Omitted image \"create-custom-action-04-outputs.png\"\\] Alt text: Example outputs configuration from step 6\n\n8.  In the Action header, select **Save** and then select **Test** to [test the action](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/test-action.md).\n\n    1.  On the Test Action screen, in the **Table** input, select any dynamically generated table choice option.\n\n        For example, select the Incident table.\n\n    2.  Select **Add Field Value**, select any field, and enter any value.\n\n        For example, select the Short description field and enter the value test.\n\n    3.  In the Dynamic inputs section and the **Reference type input** field, select a reference field value.\n\n        For example, select the user Abel Tuter.\n\n    4.  Select **Run Test**.\n\n        **Note:** Records you create from the Table API bypass data policies and required fields normally related with record creation. This action is for illustration purposes only. Use the [Create Record step](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/build-workflows/workflow-studio/create-record-action-designer.md) instead to create records with standard protections and validations.\n\n    5.  View the action's execution details.\n\n        You can use the Record Created output to verify that the runtime values for `Table` and `Field` match the test values you entered.\n\n    \\[Omitted image \"create-custom-action-06-execution-details.png\"\\] Alt text: Example action execution details from step 7\n\n9.  In the Action header, select **Publish** to make this action available to flows within the Global scope.\n\n\n### Result\n\nYou can add this action to a flow in Workflow Studio. This sample action dynamically generates a list of tables and related fields in your instance whose values that you can assign during flow design.\n\n\\[Omitted image \"example-flow-using-create-record-dynamic-inputs.png\"\\] Alt text: Example flow using the Create Record from Dynamic Inputs action\n\n"}}