getrecords
ServiceNow Examples - Mule 4
You can try the following examples.
Retrieve Records from a ServiceNow Incident Table
This example creates a Mule flow that retrieves records from the Incident table.
-
Create a Mule project in Anypoint Studio.
-
Add and configure an HTTP Listener trigger for your flow with this path:
-
Add a Transform Message component after the HTTP connector and provide a transformation script similar to this:
%dw 2.0 output application/xml ns ns0 http://www.service-now.com/incident --- { ns0#getRecords: { ns0#description: 'Test WSDL QA' } }
Add a description that matches records in your ServiceNow incident table. -
Add the Invoke operation from the ServiceNow connector after the Transform component.
-
Set up, test, and save a ServiceNow configuration for the connection to the ServiceNow server. If the connection is unsuccessful, correct any invalid connection parameters, and test again.
-
In the General tab in the navigation, set Service to
incident
and Operation togetRecords
. -
Optionally, you can choose Show Reference Values from the values (
ALL
,TRUE
,FALSE
)In Studio version 7.5.0 and later you can choose service
andoperation
keys without specifying theShow Reference Values
key to resolve the metadata. However, in earlier Studio versions, metadata won’t be loaded until you specify all of the metadata keys, and if you don’t specify all of the metadata keys, it results in a tooling exception. -
Set the Message Body to
payload
. -
Add the Transform Message component to
transform XML to JSON
for better readability. For example:%dw 2.0 output application/json --- payload
-
Add a Logger to the end of your flow that takes a
payload
(or#[payload]
) as the message. -
Deploy or Run your app.
-
Test the app by navigating to
http://localhost:8081/getrecords
The response should look similar to this example (several fields are omitted for brevity):
{ "headers": { }, "attachments": { }, "body": { "getRecordsResponse": { "getRecordsResult": { "active": "1", "activity_due": "2019-09-24 09:48:15", "approval": "not requested", "business_stc": "0", "calendar_stc": "0", "category": "Software", "child_incidents": "0", "description": "Test WSDL QA", "escalation": "0", "hold_reason": "0", "impact": "1", "incident_state": "1", "knowledge": "0", "made_sla": "1", "notify": "1", "number": "INC0011616", "opened_at": "2019-09-20 07:30:34", "opened_by": "6816f79cc0a8016401c5a33be04be441", "order": "0", "priority": "1", "reassignment_count": "0", "reopen_count": "0", "severity": "3", "state": "1", "sys_class_name": "incident", "sys_created_by": "admin", "sys_created_on": "2019-09-20 07:30:34", "sys_domain": "global", "sys_domain_path": "/", "sys_id": "c03deab4db840010a0e6e04a48961999", "sys_mod_count": "47", "sys_updated_by": "system", "sys_updated_on": "2019-09-24 07:48:15", "upon_approval": "proceed", "upon_reject": "cancel", "urgency": "1", } } } }
If you use ALL
for Show Reference Values
, the response is similar to this abbreviated output, in which the response element name for the display value field begins with dv
:
{ "headers": { }, "attachments": { }, "body": { "getRecordsResponse": { "getRecordsResult": { "active": "1", "dv_active": "true", "activity_due": "2020-05-07 13:14:19", "dv_activity_due": "2020-05-07 06:14:19", "additional_assignee_list": null, "dv_additional_assignee_list": null, "approval": "not requested", "dv_approval": "Not Yet Requested", } } } }
The response element name for the display value field is prefixed with dv
.
For more information, see ServiceNow - Display value.
Retrieve ServiceNow Incident Table Keys
This example creates a Mule flow that retrieves keys from the Incident table in a ServiceNow instance.
-
Create a Mule application as a project in Anypoint Studio 7.
-
Add and configure an HTTP Listener trigger for your flow using a Path such as this one:
/getkeys
-
Add a Transform message component after the HTTP connector.
-
Provide a transformation script similar to this (use a description that matches records in your ServiceNow incident table):
%dw 2.0 output application/xml ns ns0 http://www.service-now.com/incident --- { ns0#getKeys: { ns0#description: 'Test WSDL QA' } }
-
Add the
Invoke
operation from the ServiceNow connector after the Transform component. -
Set up, test, and save a ServiceNow configuration for the connection to the ServiceNow server. If the connection is unsuccessful, correct any invalid connection parameters and test again.
-
In the General tab navigation, set Service to
incident
and Operation togetKeys
. -
Set the Message Body to
payload
. -
Add the Transform Message component to transform XML to JSON for better readability. For example:
%dw 2.0 output application/json --- payload
-
Add a Logger to the end of your flow that takes a
payload
(or#[payload]
) as the message. -
Deploy or Run your app.
-
To test the app, navigate to:
http://localhost:8081/getkeys
-
The response should look similar to this:
{ "headers": { }, "attachments": { }, "body": { "getKeysResponse": { "sys_id": "c03deab4db840010a0e6e04a48961999,0f517ab8db840010a0e6e04a489619bc,6f1236f8db840010a0e6e04a489619f5", "count": "3" } } }