eBonding Between Two ServiceNow Instances
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago - last edited 5 hours ago
Building Connection Between the Instances
- Navigate to System Web Services > Outbound > REST Message in your source instance.
- Create a new REST Message and set the Endpoint to the target instance base URL (e.g., https://XXXXXXX.service-now.com).
- This is only the instance URL, not the API endpoint.
- Under Authentication Type, select Basic and provide credentials of a user who has access to the target instance.
2. Creating an Incident
- For creating an incident in the target instance:
- In the REST Message record, go to the HTTP Methods related list and create a new method:
- Name: Create an Incident
- HTTP Method: POST
- Endpoint: https://XXXXXXX.service-now.com/api/now/table/${tableName}
In the Content field, define the request body with variables:
{
"short_description": "${short_description}",
"caller_id": "${caller_id}",
"contact": "${contact}",
"impact": "${impact}",
"urgency": "${urgency}",
"category": "${category}"
}
Click Auto-generate variables so the variables (short_description, tableName,caller_id, contact, impact, urgency, category) are created automatically.
- Create a Business Rule on the Incident table (on Insert) to pass these variables to the REST Message:
(function executeRule(current, previous /*null when async*/ ) {
var tableName = current.getTableName();
var incident = new sn_ws.RESTMessageV2('ServiceNow Ebonding', 'Create an Incident');
incident.setStringParameterNoEscape("tableName", tableName);
incident.setStringParameterNoEscape("short_description", current.short_description);
incident.setStringParameterNoEscape("caller_id", current.caller_id);
incident.setStringParameterNoEscape("contact", current.contact);
incident.setStringParameterNoEscape("impact", current.impact);
incident.setStringParameterNoEscape("urgency", current.urgency);
incident.setStringParameterNoEscape("category", current.category);
var response = incident.execute();
var responseBody = response.getBody();
var responseObj = JSON.parse(responseBody);
if (responseObj.result && responseObj.result.number) {
current.correlation_id = responseObj.result.number;
current.u_incident_number = responseObj.result.sys_id;
current.update();
}
})(current, previous);
3. Updating Comments on Incident
- For updating comments on an existing incident:
- In the REST Message, create another HTTP Method:
- Name: Update an Incident
- HTTP Method: PATCH
- Endpoint: https://XXXXXXX.service-now.com/api/now/table/${tableName}/${sys_id}
In the Content field, define the request body:
{
"comments": "${comments}"
}
Click Auto-generate variables so the comments,tableName,sys_id variable is available.
- Create a Business Rule on the Incident table (on Update when comments change) to pass the variable to the REST Message:
(function executeRule(current, previous /*null when async*/ ) {
var incidentNumber = current.correlation_id;
var latestComment = current.comments.getJournalEntry(1);
var comments = latestComment.replace(/\r?\n|\r/g, ' ');
gs.info("Latest Comment: " + latestComment);
var tableName = current.getTableName();
var incident = new sn_ws.RESTMessageV2('ServiceNow Ebonding', 'Update Incident');
incident.setStringParameterNoEscape('tableName', tableName);
incident.setStringParameterNoEscape('sys_id', current.u_incident_number);
incident.setStringParameterNoEscape('comments', comments);
var response = incident.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.info("Response Status: " + httpStatus);
gs.info("Response Body: " + responseBody);
})(current, previous);