API access to Workflow Studio flows
Summarize
Summary of API access to Workflow Studio flows
ServiceNow enables application developers to interact programmatically with Workflow Studio flows, subflows, and actions through dedicated APIs. This capability allows triggering and managing workflows both from server-side and client-side scripts, enhancing automation and integration within your applications.
Show less
Key Features
- Server-side API (FlowAPI): Allows synchronous or asynchronous triggering of flows, subflows, and actions from server scripts, optionally including execution details.
- Client-side API (GlideFlow): Enables client-side interactions with flows, subflows, and actions, provided that these elements are explicitly marked as client callable during their design.
- Quick Methods: Specialized FlowAPI methods (e.g., executeActionQuick(), startFlowQuick()) facilitate high-performance execution by skipping record-keeping overhead, ideal for high-volume production environments.
- Streaming APIs: JSONStreamingBuilder and XMLStreamingBuilder support creating large JSON or XML payloads for REST or SOAP requests, useful for bulk data exchange with external services.
- Client Callable Option: Designers can enable individual flows, subflows, or actions to be invoked from client scripts by activating the Client callable setting during design.
- Run As Support: Flows and subflows can be configured to run either as the system user or the initiating user. However, quick API methods always run as the system user, while actions run as the initiating user.
- Code Snippets: Developers can generate JavaScript code snippets for calling specific published flows, subflows, or actions, facilitating easy integration into business rules, background scripts, or client scripts.
What This Enables You to Do
- Trigger and manage Workflow Studio flows programmatically from both server and client contexts.
- Optimize performance for large-scale or high-frequency workflow executions using quick methods.
- Integrate Workflow Studio with external systems efficiently via streaming JSON/XML payloads.
- Control workflow execution context and permissions with run as settings.
- Simplify development by generating ready-to-use code snippets tailored to your workflows.
Practical Considerations
- Ensure that flows, subflows, and actions intended for client-side invocation are marked as Client callable during design.
- Understand that quick methods bypass execution tracking and always run as the system user, which may affect auditing and context-sensitive logic.
- Code snippets are only generated for published workflow elements, so draft or modified workflows will not produce these snippets.
Application developers can access Workflow Studio functionality through APIs for flows, subflows, and actions. Flow authors can enable individual flows, subflows, and actions to be client callable during design.
Available Workflow Studio flow APIs
Trigger flows, subflows, and actions using these APIs from server or client scripts.
- Server side
- FlowAPI: Trigger a flow, subflow, or action using synchronous or asynchronous methods, with or without execution details.
- Client side
- GlideFlow: Perform client-side interactions with actions, flows, and subflows. Flow designers must enable a flow, subflow, and action to be called from the client.
FlowAPI quick methods
Use quick methods in the FlowAPI class to run an action, flow, or subflow from a server-side script without creating execution details or other related records. Use these methods to increase the speed of high-volume processing in a production environment, and to improve performance by eliminating record-keeping overhead. Methods include:
- executeActionQuick(), executeFlowQuick(), executeSubflowQuick(): Run an action, flow, or subflow from a server-side script synchronously from the current user session.
- startActionQuick(), startFlowQuick(), startSubflowQuick(): Run an action, flow, or subflow from a server-side script asynchronously.
XML and JSON streaming APIs
Builds a large streaming or non-streaming JSON or XML payload to use in a REST or SOAP request to send bulk data to a third-party API. For example, you can use these APIs to create a JSON payload in the Workflow Studio Script step and pass the returned value to the REST step to send the request to a third-party service. For more information, see JSONStreamingBuilder and XMLStreamingBuilder .
Client callable APIs
By default, the flows, subflows, and actions can only be called by the FlowAPI within a server script. Flow and action designers can make individual flows, subflows, or actions available to client calls by enabling the Client callable option during the design process.
Run as support
Flows and subflows can run as either the system user or the user who initiates the session. Set this behavior from the flow properties. All API quick methods ignore the run as property, and always run as the system user.
Actions always run as the user who initiates the session.
Code snippets
Application developers can generate a JavaScript function that calls a specific flow, subflow, or action with the Code Snippet option. Use the code snippet in scripts such as business rules or the Scripts - Backgound module to call specific Workflow Studio elements. The system only generates code snippets for published flows, subflows, and actions. Workflow Studio elements in the draft or modified status do not generate code snippets.