
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
The JSON API has been widely used for ServiceNow. The purpose of this blog is to explore all JSON data-related APIs to learn how their features can be used to manage JSON data through the flow action of a flow designer. This blog will provide you with all useful use cases that can help you with your web service (Rest and Soap) integration as well as Catalog item flow through Flow Designer.
Objectives
- Flow Designer JSON APIs and their showcases
- JSONStreamingBuilder - Scoped
- JSONStreamingAPI - Scoped
- JSON
- JSON 3 Conversion Approach Script showcases in Flow Action
- Convert Array Of Strings to Array of Objects
- Convert String to Array of Objects
- Convert gliderecord to a JSON object
- SONv2 web service
- GlideJsonPath - Global
JSON API
The JSON API has dynamic and static methods. You access the dynamic methods by creating a JSON object. To use the dynamic methods in a scoped application, add the global prefix when calling the constructor. You access the static methods by using the static JSON object.
Convert an array of Strings to an array of Objects in action designer.
- Define input json_arry as a type of JSON in Action Designer
- Define Output variable – list_of_objects is defined on step 1 below
- Creating the script on step 2 in above
Convert a string to an array of Objects in Action Designer.
- Define Input comma_delimited_string_list as a type of String in Action Designer
- Define the Output variable - list_of_objects on a step 1
- Creating the script on step 2 in above
Flow Designer JSON APIs
JSONStreamingBuilder
JSONStreamingBuilder initiates the JSONStreamingBuilder object to build a large streaming JSON payload to use in a REST or SOAP request in the Flow Designer script step with the sn_ih namespace identifier. JSONStreamingBuilder() uses its build() method to return a JSONStreamingAPI object.
The JSONStreamingBuilder object has the build() method, which returns a JSONStreamingAPI object. The JSONStreamingAPI object. has the following methods to build the payload:
- startObject(): Creates the parent JSON object.
- Methods to generate the JSON key-value pairs, such as writeFieldName(), writeString(), and writeNumberField().
- endObject(): Closes the parent JSON object.
- getJSONString() or getAttachmentId(): Returns the JSON string or attachment ID that you created.
- close(): Closes the JSONStreamingAPI object.
JSONStreamingBuilder Flow Action Use Case 1-Create Json Payload
- Create new Action in Action Designer
- Create the following script used within Script Step section to build the Payload:
- Create JSONStreamingBuilder object and call .build method
- Call startObject() method.
- Call eddObject() method.
- Call startArray() method
- Call endArray() method
- Define output variable "payload" to hold the created payload.
- The Action created in Action Designer
- Output (test your action)
SONStreamingBuilder Flow Action Use Case 2-Create the attachment
Create a JSON object and store it in the Attachment [sys_attachment] table with a defined expiration date.
- Create the following script within the Script section of Action Designer
- Action created in Action Designer
- Testing Output- the attachment sysid
JSONv2 web service
This is a platform-level processor similar to the services for SOAP, WSDL, CSV, Excel, and XML. Like those services, the JSON web service is triggered by a standalone JSONv2 URL parameter like below
GlideJsonPath - Global
The GlideJsonPath API Instantiates a GlideJsonPath scriptable object by parsing a JSON document like
Convert a gliderecord to a JSON object Use Case
You can use JSON stringify(Object jsonObject) method to covert gliderecord to JSON object like below:
- Script Step in Action Designer
- Output (after running a test)
If you enjoy my ServiceNow posts, please be sure to follow me on LinkedIn and my ServiceNow YouTubes Channels
- 2,313 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.