Data Stream actions and pagination
Summarize
Summary of Data Stream actions and pagination
Data Stream actions in ServiceNow allow you to send REST, SOAP, or JDBC requests from Workflow Studio to APIs that return large streams of data (over 10 MB) or paginated results. These actions parse the streamed data into complex object outputs, which can be further used in flows to automate processing large datasets, such as importing employee or document data from third-party sources into ServiceNow tables.
Show less
Note that Data Stream actions require an Integration Hub subscription.
Key Features
- Handling large data: Parse and format response streams larger than 10 MB efficiently.
- Automatic pagination: Send multiple API requests automatically to retrieve paginated results using configurable pagination setup steps.
- Flow integration: Easily incorporate Data Stream actions in flows using For each flow logic to process each object individually.
- Reusable actions: Create Data Stream actions once and reuse them across multiple flows.
- Request configuration: Supports preprocessing scripts, connection retrieval, REST, SOAP, and JDBC requests, with transformation scripting for data formatting.
- Parsing capabilities: Use Splitter steps to identify data elements and Script Parser steps to map data into complex objects.
- JDBC support: Handle JDBC data streams without pagination; transform scripts can be used to specify data mapping.
- Error handling: Customize error evaluation to catch and define error behaviors for each step.
- Execution monitoring: View detailed execution results including pagination pages, item counts, and errors.
Using Data Stream Actions
Data Stream actions can be run from within a flow—where each item in the data stream is processed with For each logic—or triggered via script using the executeDataStreamAction() method in the FlowAPI class.
When added to flows, Data Stream actions automatically wrap within For each flow logic blocks, enabling easy record creation for each streamed object.
Configuration Highlights
- Action Outline: Structured steps cannot be manually added; steps are added or removed through configuration options.
- Preprocessing: Optionally retrieve connection info or run scripts before the initial API request.
- Request Setup: Configure pagination with templates or custom scripts; REST/SOAP requests run per page, while JDBC retrieves all data at once.
- Parsing: Split response streams into individual objects and map them using script parsers to complex output objects.
- REST Parsing Automation: Use the Test REST step to auto-generate parsing and output configurations.
- JDBC Considerations: No pagination or parsing steps required; supports asynchronous execution with MID Server and configurable timeouts.
Execution and Monitoring
You can review execution details for individual items and pages, including request counts and error statistics. The number of items or pages displayed can be adjusted through system properties. For JDBC data streams, testing queries and reviewing results is supported without needing complex output schema construction.
Design Considerations
- Ensure MID Server availability for data retrieval where needed.
- Plan for error handling and transaction counts, as each API request counts as a transaction.
- Be mindful of performance impacts when configuring detailed execution logging, especially for large numbers of pages.
Practical Benefits for ServiceNow Customers
Data Stream actions simplify integration with external APIs that return large or paginated datasets, eliminating the need for complex custom coding. They enable flow designers to process and transform large volumes of data efficiently within ServiceNow flows, support reusable configurations, and provide robust monitoring and error handling. This capability enhances automation scenarios such as bulk data imports, synchronization, and data transformation, improving operational efficiency and data consistency.
Send REST, SOAP, or JDBC requests from Workflow Studio to APIs that return a stream of response data larger than 10 MB, or that return paginated results. Parse stream data into a series of complex object outputs and use the data pills in other actions in a flow.
Benefits
Data Stream actions offer these benefits.
- Parse and format a stream of response data larger than 10 MB.
- Automatically send multiple requests to APIs that paginate results, if applicable.
- Can be used in Integration Hub - Import and to create a data source.
- Enable flow designers to process large requests without complex coding or configuration.
- Enable flow designers to process each object within a data stream using For each flow logic. For example, you might create a Data Stream action that imports document data from a third-party site. When you add the action to a flow, Workflow Studio automatically adds the action to a For each flow logic block, enabling flow designers to easily create a record in ServiceNow for each object in the data stream. See Use a Data Stream action in a flow.
- Enable flow designers to reuse Data Stream actions in multiple flows, using the same source of data in multiple ways.
Running a Data Stream action
There are two ways to run a Data Stream action.
- From a flow
- You can process each object within a data stream using For each flow logic. For example, you might create a Data Stream action that imports document data from a third-party site. When you add the action to a flow, Workflow Studio automatically adds the action to a For each flow logic block, enabling flow designers to easily create a record in ServiceNow for each object in the data stream. See Use a Data Stream action in a flow.
- From a script
- You can start a Data Stream using the executeDataStreamAction() method in the FlowAPI class. For more information, see FlowAPI.
Action outline
Data Stream actions follow a set structure. Follow prompts to add and remove steps from the action outline. You cannot manually add steps to a Data Stream action.
Action error evaluation
Use error evaluation to catch step errors and specify the error behavior of each step you add to a data stream action. You can also create your own error conditions by specifying when an action returns an error state as well as the status codes and messages they return.
Action Preprocessing
Use the Action Preprocessing category to retrieve connection and credential details or to run a preprocessing script.
Select Retrieve connection info to retrieve connection and credential details to use in your action. Selecting this option adds the Get Connection Info step as the first step in the action preprocessing. For more information, see Get Connection Info step.
Select Enable preprocessing script to run a preprocessing script before the action sends the initial API request. For example, validate action inputs or set default values. Selecting this option adds a script step to the Data Stream action. For more information, see Script step.
Preprocessing executes once per action, before the first API request.
This is an optional Data Stream action component that runs on either the instance or a MID Server.
Request
Use the Request category to configure how the action sends API requests. The Request section executes once per page of results. Request components provide these configuration options.
- Pagination Setup step
Request results in batches. Once one page of data is processed, the Data Stream action runs the request section again to return the next set of results. Use the pagination setup step to set up pagination options required by the API. Configure the Pagination Setup step manually, or select a pre-built template to apply common configurations. For example, apply the Limit / Offset template to specify the number of items you want returned per page (limit), and the starting number for the first item (offset). After applying a template, update the values to ensure that the configuration complies with the API's requirements.
Note:For licensing purposes, each request counts as one transaction, including each request for the next page of results.The value of the reserved, read-only
getNextPagevariable determines whether to request another page of results. As long as thegetNextPagevariable is true and the previous page contains data, the action continues to send requests for the next page.Note:You must explicitly set the value to true in the script or it will default to false.This is an optional Request component that only runs on the instance.Note:Pagination isn't applicable to the JDBC step.- Script step
Run a script before every request for the next page of results. Use this script for data validation and transformation when calling a paginated API. For example, generate a JSON payload for the next page request. Selecting this option adds a script step to the Data Stream action. For more information, see Script step.
This is an optional Request component that runs on either the instance or a MID Server.
- REST or SOAP step
Send a REST or SOAP request to a third-party API. Select a data format to add an associated step to the Data Stream action. For more information, see REST step and SOAP step.
This is a mandatory Request component that runs on either the instance or a MID Server.
- JDBC step
Send a JDBC request to a third-party API. Use transform script to format data and add an associated step to the Data Stream action. For more information, see JDBC step and Test JDBC step. All data is retrieved and pagination is not needed.
This is a mandatory Request component that runs on a MID Server.
Parsing in REST and SOAP steps
- REST or SOAP step Response Body, Stream, or Error Message outputs
- Splitter step outputs
For more information about complex data, see Complex data. Parsing components provide these configuration options.
- Splitter step
Identify the parent node in the response stream to map to a complex object. For example, identify a user element in an XML payload to create a complex object for each user in the response stream.
Select a splitter type to identify and separate repeated items in an XML or JSON data stream.
- JSON: Identifies objects from a stream of JSON data. Use a JSONPath expression to identify a JSON array containing repeated data.
- XML: Identify objects from a stream of XML data. Use an XPath expression to identify an XML element containing repeated data.
This is a mandatory Parsing component that only runs on the instance.
- Script Parser step
Use JavaScript and ServiceNow APIs to map items in the response stream to a complex object output represented by the
targetObjectglobal object. For example, map incident record elements identified in the splitter step to a complex object containing incident fields. If the data stream includes siblings to the item identified in the splitter step that you do not want mapped to a complex object, include conditions to exclude those items. You can skip items in the stream by addingoutputs.state = 'SKIP'wherever needed to the script section of the Script Parser step.This is a mandatory Parsing component that only runs on the instance.
Generate the parsing phase for REST-based Data Stream actions
You can automatically configure the splitter step, script parser step, and outputs for REST-based Data Stream actions. The Test REST step functionality in REST-based Data Stream actions executes a request to the configured REST endpoint, analyzes the response payload, and automatically sets up the parsing and output components.
When a REST step is added to the Request section of a Data Stream action, you can use the REST step's Test REST Step button to auto-generate the Parsing section and Outputs. The Parsing section includes the splitter step and parser step. Auto-generating also puts complex object output in the Outputs section.
Transform script in JDBC step
JDBC data stream action doesn't require pagination. Also, splitter and parser steps aren't required.
JDBC operations and MID Server timeouts
For JDBC operations, execute the Data Stream Action asynchronously and poll the Attachments [sys_attachment] table for results.
The MID Server processes the SQL statement, while the instance/main thread waits for context payloads to be inserted into the attachment table to query the next record.
You can adjust timeout values for JDBC operations with the following properties.
- com.snc.process_flow.datastream.payload.timeout.seconds
- The amount of time the instance waits for the payload to be available from the JDBC execution in the MID Server. A bounded property with a minimum value of 0 seconds and a maximum value of 7200 seconds. The default time is 600 seconds.
- com.snc.process_flow.datastream.async_child.timeout.seconds
- The amount of time allocated for the execution of a child plan in the MID Server.A bounded property with a minimum value of 0 seconds and a maximum value of 7200 seconds. The default time is 60 seconds.
Data Stream outputs in SOAP and REST steps
When designing a Data Stream action, you must create a single output of type Object or Dynamic Object. The Script Parser step maps items in the stream to this object using the
targetObject global object.
At runtime, the system splits and parses the stream of response data according to the Data Stream configuration. Each item in the stream maps to the complex object structure defined by the Script Parser step and the object output, resulting in a large series of complex objects. For more information about complex data, see Complex data.
Data Stream outputs in JDBC step
- You can only retrieve data and can't update or delete records using the JDBC data stream action.
- The fields, Maximum Row and Maximum Payload Size (KB) that are available in JDBC step aren't available in the JDBC data stream action.
Execution details in REST and SOAP steps
View the configuration and runtime results for each item processed by a Data Stream action. Select a record number to see its configuration and runtime details. By default, the execution details include requests for the last 1000 items. To change the number of items in the execution details, update the com.snc.process_flow.reporting.datastream.item.lastn system property.
- Data stream summary
View an overview of the execution that includes this information.
- Page count: Number of pages returned by a paginated API.
- Total item count: Number of items in the response stream mapped to complex object outputs.
- Error count: Number of errors encountered.
- Page details
View runtime data for each step within the Data Stream action. Select a page to view runtime details for each request to a paginated API. By default, the execution details include requests for the last five pages. To change the number of requests in the execution details, update the com.snc.process_flow.page.reporting.lastn system property. Set the value to 0 to remove pages from the execution details and -1 to include all pages.
Note:Including all pages can affect performance and is not recommended.
Execution details in JDBC step
Construction of the output complex object schema isn't needed for the JDBC data stream action. You can test the query and see the query result. See Test JDBC step for more information. Configure the MID Server properties mid.jdbc.datastream.max.record.size and mid.jdbc.datastream.fail.when.attachement.limit.exceeded to retrieve data as per your requirement. See MID Server properties for more information.