-
Service:
incident
-
Operation:
getRecords
ServiceNow Connector 6.11 Examples - Mule 4
To fully benefit from using Anypoint Connector for ServiceNow (ServiceNow Connector), see the following examples of configuring the connector both in Anypoint Studio and Flow Designer.
Retrieve a ServiceNow Incident Record
This example creates a Mule flow in Flow Designer to retrieve a record based on an incident number:
-
Create a Mule application as a project in Flow Designer.
-
Add and configure an HTTP Listener as a source for your flow, and set the Path to
/incident/get
.Or, use the default configuration for the HTTP Listener connection.
-
Add the ServiceNow Invoke operation to your flow.
-
Set up and test a ServiceNow configuration for the connection to the ServiceNow server, for example:
-
Configuration Name:
ServiceNow_Config
-
Username:
my_user_name
-
Password:
my_password
-
Service Address:
https://my_account.service-now.com
-
ServiceNow Version:
Quebec
Your ServiceNow account must either have the soap
role set or be anadmin
account. Admin accounts automatically have access to SOAP and are preferred for testing. However, for production, create a dedicated API account with thesoap
role and any additional roles set to grant minimal necessary access.
If the connection test is unsuccessful, correct any invalid connection parameters and retest the connection.
-
-
In the Transport tab for the ServiceNow configuration, set up, test, and save a
Basic Auth HTTP
Message Dispatcher.Use the same username and password that you provided in the General tab, for example:
-
Username:
my_user_name
-
Password:
my_password
If the connection test is unsuccessful, correct any invalid connection parameters and retest the connection.
-
-
Select the Web Service Configuration values for the ServiceNow connector, for example:
-
Make these values available as menu items in the Service and Operation fields.
The names become available once the connector loads the metadata for them.
Do not add these names manually. -
Provide a transformation script for the connector.
-
From the Invoke operation in Design Center, click Map for the Body field.
-
Click the Script tab at the bottom of the Body window.
-
Copy and paste in the transformation script as in this example:
%dw 2.0 output application/xml ns inc http://www.service-now.com/incident --- { inc#getRecords: { inc#number: "INC0012345" } }
This example changes the output
data type toapplication/xml
. -
Add a Logger to the end of your flow that takes
payload
as the message. -
Deploy, sync, or run the app.
-
Test the app by opening the URL
http://url.for.your.app:8081/incident/get
from a browser or from an app such as Postman.The response should look similar to this example (several fields omitted for brevity):
<getRecordsResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <getRecordsResult> <active>1</active> <additional_assignee_list/> <approval>not requested</approval> <business_stc>0</business_stc> <calendar_duration/> <calendar_stc>0</calendar_stc> <caller_id>6816f79cc0a8016401c5a33be04be441</caller_id> <category>inquiry</category> <escalation>0</escalation> <knowledge>0</knowledge> <made_sla>1</made_sla> <notify>1</notify> <number>INC0021195</number> <opened_at>2017-07-27 03:13:54</opened_at> <opened_by>6816f79cc0a8016401c5a33be04be441</opened_by> <order>0</order> <priority>5</priority> <short_description>Server outage</short_description> <state>1</state> <sys_class_name>incident</sys_class_name> <sys_created_by>admin</sys_created_by> <sys_created_on>2017-07-27 03:14:52</sys_created_on> <sys_domain>global</sys_domain> </getRecordsResult> </getRecordsResponse>
Retrieve Records from a ServiceNow Incident Table
This example creates a Mule flow in Studio to retrieve records from the Incident
table. The following screenshot shows the Studio app flow for this example:

-
Create a Mule project in Studio.
-
Add and configure an HTTP Listener trigger for your flow with this path:
getrecords
-
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 ServiceNow 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, choose Show Reference Values from the values (
ALL
,TRUE
,FALSE
)In Studio 7.5.0 and later, you can choose the 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 component 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 in Studio to retrieve keys from the Incident table in a ServiceNow instance:
-
Create a Mule application as a project in Studio.
-
Add and configure an HTTP Listener trigger for your flow, and set the Path to
/getkeys
. -
Add a Transform Message component after the HTTP Listener operation.
-
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 ServiceNow Invoke operation after the Transform Message 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 component 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" } } }