Get started with dynamic outputs
- UpdatedJan 30, 2025
- 13 minutes to read
- Yokohama
- Create Workflows
Create a sample action that builds dynamic outputs for use in a flow.
Before you begin
Procedure
-
Create connection and credential records for dynamic outputs
This connection & credential alias will provide the base URL and user account needed to configure the REST steps of your data gathering actions.
-
Create a data gathering action to get a record schema
This data gathering action will convert a single record into a JSON object for a record dynamic output.
-
Create a data gathering action to get an array of records schema
This data gathering action will convert a list of records record into JSON array of objects for a records dynamic output.
-
Create a custom action to test dynamic outputs
This custom action illustrates two types of dynamic output data. One dynamic output generates an object for a single record. Another dynamic output generates an array of objects for a list of records.
Create connection and credential records for dynamic outputs
Create the aliases, connections, and credentials that REST steps will use to connect to your local instance.
Before you begin
Role required: admin
Procedure
- Navigate to All > Connections & Credentials > Credentials.
-
Select New, select Basic Auth Credentials, and enter these field values.
- For Name, enter Local Admin.
-
For User name, enter a user account with access to Flow Designer and the REST API.
For example, enter admin.
- For Password, enter the account password.
- Select Submit to create the credential record.
- Navigate to All > Connections & Credentials > Connection & Credential Aliases.
-
Select New and enter these fields values.
- For Name, enter Local Instance.
- Accept the default value of HTTP for the Connection type.
- Select Submit to create the Connection & Credential Alias record.
-
Select the alias you created.
For example, select Local Instance.
-
From the Connections related list, select New, and enter these field values.
- For Name, enter My Instance.
-
For Credential, select the basic authentication credential record you created.
For example, select the Local Admin credential.
-
For Connection URL, enter the base URL for your instance including the forward slash at the end.
Include the URL prefix https:// and add a slash character at the end of the URL.For example, https://example.service-now.com/.
- Select Submit to create the HTTP(s) Connection record.
Create a data gathering action to get a record schema
Create a data gathering action to look up a table schema and convert into a JSON object.
Before you begin
About this task
- A REST step to gather table schema data for a selected table. The REST step Response Body is in JSON format.
- A script step to transform the REST step's JSON Response Body into a dynamic object. The dynamic object consists of JSON name-value pairs, where there is an entry for each field in the table.
- An output variable named
output
of type JSON to store the dynamic object.
Procedure
- Navigate to All > Process Automation > Workflow Studio.
- On the homepage, select Actions.
-
Select New and select New Action.
- On the Action Properties screen, in the Name field, enter Get ServiceNow Object Schema (Dynamic).
- Select Submit.
-
In the Action Outline, select Inputs.
- In the Action Input header, select Create Input.
- In the Label and Name fields, enter Table.
- In the Type field, select String.
- To make this input required, toggle the Mandatory slider so that it is active.
-
In the Action Outline, select the add a new step icon (
) under Inputs and select REST Step.
-
Under the REST step header, fill in the following fields.
Field Value Connection Leave the Use Connection Alias option selected. Connection Alias select the create new record icon ( ) to create a new Create an HTTP(s) connection, or use an existing connection for your instance. The Credential for the HTTP(s) connection must use Basic authentication credentials. 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 and Getting started with credentials.
Build Request Leave the Manually option selected. Resource Path Enter api/now/processflow/table/ and then select the data pill picker ( ). Select Inputs > Table. Next, enter /schema.
HTTP Method Enter GET Query Parameters select the plus icon ( to add a new query parameter. Then, in the Name field, enter get_choices and true in the Value field.
-
In the Action Outline, select the add a new step icon (
) under your REST step and select the Script step.
- In the Input Variables section, select Create Variable.
- In the Name field, enter payload.
-
Next to the Value field, select the data pill picker (
) and select REST Step > Response Body.
-
In the Script field, enter the following code.
(function execute(inputs, outputs) { var payload = JSON.parse(inputs.payload); var columns = payload.result.data.columns; var schema = columns.map(function(column) { var value = { label: column.label, name: column.name, type: getCOType(column.definition.base_type), }; if (column.definition.type === 'choice') { value.type = 'choice'; value.choices = column.definition.choices; } if (column.definition.base_type === 'GUID') { value.children = [ { label: 'Link', name: 'link', type: 'string' }, { label: 'Value', name: 'value', type: 'string' }, ]; } return value; }); outputs.schema = { data: { type: 'object', children: schema, }, }; function getCOType(type) { if (type === 'GUID') return 'reference'; return type; } })(inputs, outputs);
- In the Output Variables section, select Create Variable.
- In the Label and Name fields, enter schema.
- In the Type field, select JSON.
-
In the Action Outline, select Outputs.
- In the Action Output header, select Create Output.
- In the Label and Name fields, enter output.
- In the Type field, select JSON.
- In the Action Output header, select Exit Edit Mode.
-
Next to the Value field, select the data pill picker (
) and select Script Step > schema.
-
In the Action header, select Save and then select Test to test the action.
- On the Test Action screen, enter incident for the Table input.
- Select Run Test.
- Check the action's execution details.
Your data gathering action runs successfully if the runtime value forfields
is a complex object in a format that is similar to the following abbreviated example.{ "data": { "type": "object", "children": [ { "name": "active", "label": "Active", "type": "boolean" }, { "name": "activity_due", "label": "Activity due", "type": "datetime" }, ...
- In the Action header, select Publish to make the Get ServiceNow Object Schema (Dynamic) action available to other flows and actions within the Global scope.
Create a data gathering action to get an array of records schema
Create a data gathering action to generate an array of objects from a list of records.
Before you begin
About this task
- A REST step to gather table schema data for a selected table. The REST step Response Body is in JSON format.
- A script step to transform the REST step's JSON Response Body into a dynamic object. The dynamic object consists of a JSON array of objects, where each source record is converted into one object of the array.
- An output variable named
output
of type JSON to store the dynamic object.
Procedure
- Navigate to All > Process Automation > Workflow Studio.
- On the homepage, select Actions.
-
Select New and select New Action.
- On the Action Properties screen, in the Name field, enter Get ServiceNow Array.Object Schema (Dynamic).
- Select Submit.
-
In the Action Outline, select Inputs.
- In the Action Input header, select Create Input.
- In the Label and Name fields, enter Table.
- In the Type field, select String.
- To make the input required, toggle the Mandatory slider so that it is active.
-
In the Action Outline, select the add a new step icon (
) under Inputs and select the REST step.
-
Under the REST step header, fill in the following fields.
Field Value Connection Leave Use Connection Alias selected. Connection Alias select the create new record icon ( ) to create a new Create an HTTP(s) connection, or use an existing connection for your instance. The Credential for the HTTP(s) connection must use Basic authentication credentials. Additionally, the Connection URL must be the base URL for your instance, including the forward slash at the end.
Build Request Leave Manually selected. Resource Path Enter api/now/processflow/table/ and then select the data pill picker ( ). Select Inputs > Table. Finally, enter /schema
HTTP Method Enter GET Query Parameters select the plus icon ( to add a new query parameter. Then, in the Name field, enter get_choices and truein the Value field.
-
In the Action Outline, select the Add a new step(
) icon under your REST step and select the Script step.
- In the Input Variables section, select Create Variable.
- In the Name field, enter payload.
-
Next to the Value field, select the data pill picker (
) and select REST Step > Response Body.
-
In the Script field, enter the following code.
(function execute(inputs, outputs) { var payload = JSON.parse(inputs.payload); var columns = payload.result.data.columns; var schema = columns.map(function(column) { var value = { label: column.label, name: column.name, type: getCOType(column.definition.base_type), }; if (column.definition.type === 'choice') { value.type = 'choice'; value.choices = column.definition.choices; } return value; }); outputs.schema = { data: { type: 'array.object', attributes: { child_type: 'object', }, children: schema, }, }; function getCOType(type) { if (type === 'GUID') return 'string'; return type; } })(inputs, outputs);
- In the Output Variables section, select Create Variable.
- In the Label and Name fields, enter schema.
- In the Type field, select JSON.
-
In the Action Outline, select Outputs.
- On the Action Output header, select Create Output.
- Enter output in the Label field and Name field.
- Select JSON for the Type field.
- Select Exit Edit Mode.
-
Next to the Value field, select the data pill picker (
) and select Script Step > schema.
-
In the Action header, select Save and then select Test to test the action.
- On the Test Action screen, in the Table field, enter incident.
- Select Run Test.
-
Check the action's execution details.
Your data gathering action runs successfully if the runtime value for
fields
output is a complex object that contains an array of key-value pairs forlabel
,name
, andvalue
as shown in the following abbreviated example.{ "data": { "type": "array.object", "children": [ { "name": "active", "label": "Active", "type": "boolean" }, { "name": "activity_due", "label": "Activity due", "type": "datetime" }, ...
- In the Action header, select Publish to make the Get ServiceNow Array.Object Schema (Dynamic) action available to other actions within the Global scope.
Create a custom action to test dynamic outputs
Create a sample action to dynamically generate two action outputs,
Record
and Records
which refresh dynamically when the
value for the Table input changes.
Before you begin
About this task
This custom action uses two data gathering actions to populate dynamic outputs.
Procedure
-
In the main header, select the create flow, subflow, or action icon (
) and select Action.
- In the Action Properties modal, in the Name field, enter Get ServiceNow Records (Dynamic).
- Select Submit.
-
In the Action Outline, select Inputs.
- In the Action Input header, select Create Input.
- In the Label and Name fields, enter Table.
- In the Type field, select Dynamic Choice.
- To make the input required, toggle the Mandatory slider so that it is active.
-
Select the Toggle advanced inputs icon (
to display the advanced options for the
Table
input. - In the Default value field, enter incident.
- Under Dynamic Options, in the Action field, select Get ServiceNow Tables - Dynamic.
- Select Create Input to create another action input.
- In the Label and Name fields, enter NumberOfRecords.
- In the Type field, select Integer.
- To make the input required, toggle the Mandatory slider so that it is active.
-
Select the Toggle advanced inputs icon (
to display the advanced options for the
Table
input. - In the Default value field, enter 3.
-
In the Action Outline, select the add a new step icon (
) under Inputs and select the REST step.
-
Under the REST step header, fill in the following fields.
Field Value Connection Leave Use Connection Alias selected. Connection Alias Select the create new record icon ( ) to create a new Create an HTTP(s) connection, or use an existing connection for your instance. The Credential for the HTTP(s) connection must use Basic authentication credentials. Additionally, the Connection URL must be the base URL for your instance, including the forward slash at the end.
Build Request Leave Manually selected Resource Path Enter api/now/table/ and then select the data pill picker ( ). Select Inputs > Table.
HTTP Method Enter GET Query Parameters Select the plus icon ( to add a new query parameter. Then, enter sysparm_limit in the Name field. Next to the Value field, select the data pill picker (
) and then select Inputs > NumberOfRecords.
-
In the Action Outline, select the add a new step icon (
) under Inputs and select the Script step.
- In the Input Variables section, select Create Variable.
- In the Name field, enter payload.
-
Next to the Value field, select the data pill picker (
) and select REST Step > Response Body.
-
In the Script field, enter the following code.
(function execute(inputs, outputs) { var response = JSON.parse(inputs.payload); var records = response.result; outputs.record = records[0]; outputs.records = JSON.stringify(records); })(inputs, outputs);
- In the Output Variables section, select Create Variable.
- In the Label and Name fields, enter record.
- Select JSON for the Type field.
- Toggle the Mandatory slider so that it is active.
- Select Create Variable to create another output variable for the script step.
- In the Label and Name fields, enter records.
- In the Type field, select JSON.
- To make the input required, toggle the Mandatory slider so that it is active.
-
In the Action Outline, select Outputs.
- In the Action Output header, select Create Output.
- In the Label and Name fields, enter Records.
- In the Type field, select Dynamic Object.
-
Select the Toggle advanced inputs icon (
to display the advanced options for the
Records
output. - Under Dynamic Options, select Get ServiceNow Array.Object Schema (Dynamic) as the Action.
- To make the Table input dependent on another input, toggle the Depends-On Another Input slider to make it active.
- In the Tablee field, select Table.
- In the Action Output header, select Exit Edit Mode.
-
Next to the Value field, select the data pill picker (
) and select Script Step > records.
- In the Action Output header, select Edit Outputs > Create Output to create another action output.
- In the Label and Name fields, enter Record.
- In the Type field, select Dynamic Object.
-
Select the Toggle advanced inputs icon (
to display the advanced options for the
Record
output. - Under Dynamic Options, in the Action field, select Get ServiceNow Object Schema (Dynamic).
- To make the Table input dependent on another input, toggle the Depends-On Another Input slider to make it active.
- In the Table field, select Table.
- In the Action Output header, select Exit Edit Mode.
-
For the Value, select the data pill picker (
) and select Script Step > record.
-
In the Action header, select Save and then select Test to test the action.
- On the Test Action screen, select any dynamically generated choice value for the Table input.
- Select Run Test.
-
Check the action's execution details.
Your action runs successfully if the runtime value for
Record
is a properly formatted complex object and the runtime value forRecords
is a properly formatted complex object array.
- In the Action header, select Publish to make the Get ServiceNow Records (Dynamic) action available to flows within the Global scope.
Result
You can now add the Get ServiceNow Records (Dynamic) action to a flow. This sample action dynamically generates two action outputs, Record
and Records
, which can be accessed
as data pills in the data panel. The data pills refresh dynamically when the value for the Table input changes.
On this page
Related Content
- Create a data gathering action for a dynamic object
Create an action to collect output values. Then, pass the values to a parent action as a dynamic object.
- Dynamic output configuration options
Use these options to configure your dynamic outputs for a parent action.