ServiceNow Connector 6.17 Examples | MuleSoft Documentation
# ServiceNow Connector 6.17 Examples
To fully benefit from using Anypoint Connector for ServiceNow (ServiceNow Connector), see the following examples.
## Retrieve Records from a ServiceNow Incident Table
This example creates a Mule flow that retrieves records from the `Incident` table. The following screenshot shows the Studio app flow for this example:
Figure 1. App flow for the Retrieve Records example
  1. Create a Mule project in Studio.
  2. Add and configure an **HTTP Listener** trigger for your flow with this path:
  3. 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.   
---  
  4. Add the **Invoke** operation from ServiceNow after the **Transform** component.
  5. 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.
  6. In the **General** tab in the navigation, set **Service** to `incident` and **Operation** to `getRecords`.
  7. Optionally, choose **Show Reference Values** from the values (`ALL`, `TRUE`, `FALSE`)
In Studio 7.5.0 and later, you can choose the `service` and `operation` keys without specifying the `Show 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.   
---  
  8. Set the Message Body to `payload`.
  9. Add the **Transform Message** component to `transform XML to JSON` for better readability. For example:
```
%dw 2.0
output application/json
---
payload
```

  10. Add a **Logger** component to the end of your flow that takes a `payload` (or `#[payload]`) as the message.
  11. Deploy or run your app.
  12. 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`.
## Retrieve ServiceNow Incident Table Keys
This example creates a Mule flow that retrieve keys from the Incident table in a ServiceNow instance:
  1. Create a Mule application as a project in Studio.
  2. Add and configure an HTTP **Listener** trigger for your flow, and set the **Path** to `/getkeys`.
  3. Add a **Transform Message** component after the HTTP **Listener** operation.
  4. 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'
	}
}
```

  5. Add the ServiceNow **Invoke** operation after the **Transform Message** component.
  6. 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.
  7. In the **General** tab navigation, set **Service** to `incident` and **Operation** to `getKeys`.
  8. Set the Message Body to `payload`.
  9. Add the **Transform Message** component to transform XML to JSON for better readability. For example:
```
%dw 2.0
output application/json
---
payload
```

  10. Add a **Logger** component to the end of your flow that takes a `payload` (or `#[payload]`) as the message.
  11. Deploy or run your app.
  12. To test the app, navigate to: `http://localhost:8081/getkeys`
  13. The response should look similar to this:
```
{
 "headers": {
 },
 "attachments": {
 },
 "body": {
  "getKeysResponse": {
   "sys_id": "c03deab4db840010a0e6e04a48961999,0f517ab8db840010a0e6e04a489619bc,6f1236f8db840010a0e6e04a489619f5",
   "count": "3"
  }
 }
}
```



## See Also
  * Introduction to Anypoint Connectors
  * Using Anypoint Studio to Configure ServiceNow Connector
  * MuleSoft Help Center