- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 01:36 AM
In this article, I have provided five key (steps) on how to create an incident from one instance to another
Integrating ServiceNow instances using REST API can streamline incident management and ensure seamless communication between different environments. This guide will walk you through the process of creating an incident in one ServiceNow instance from another instance using REST API.
Prerequisites:
- ServiceNow Instances: Ensure you have access to both the source and target ServiceNow instances.
- REST API Access: Verify that REST API access is enabled on both instances.
- Credentials: Have the appropriate API credentials (username and password) for authentication.
Five (5) Key Steps to Create an Incident from One Instance to Another:
1. Obtain the Target Instance API Endpoint
The target instance is where the incident will be created. You’ll need the instance URL and the REST API endpoint for incidents.
Example Target Instance URL: https://target-instance.service-now.com
API Endpoint for Incident Creation: /api/now/table/incident
2. Prepare the REST API Request
To create an incident on the target instance, you'll send an HTTP POST request with the required incident details.
HTTP Method: POST
Request URL: https://target-instance.service-now.com/api/now/table/incident
Headers:
- Authorization: Basic Authentication (base64 encoded username:password)
- Content-Type: application/json
Body: Include the details for the incident you want to create.
Example JSON Body:
{
"short_description": "Incident created from external instance",
"description": "Details about the incident",
"category": "Software",
"priority": "2"
}
3. Configure the Source Instance to Make the API Call
On the source instance, you can use a Business Rule, Script Include, or IntegrationHub to call the target instance API.
Example Using Script Include: Create a Script Include that makes an HTTP POST request to the target instance API.
var targetInstanceUrl = 'https://target-instance.service-now.com/api/now/table/incident';
var targetUsername = 'your_username';
var targetPassword = 'your_password';
function createIncident() {
var request = new sn_ws.RESTMessageV2();
request.setEndpoint(targetInstanceUrl);
request.setHttpMethod('POST');
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestHeader('Authorization', 'Basic ' + GlideStringUtil.base64Encode(targetUsername + ':' + targetPassword));
var requestBody = {
"short_description": "Incident created from external instance",
"description": "Details about the incident",
"category": "Software",
"priority": "2"
};
request.setRequestBody(JSON.stringify(requestBody));
var response = request.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.info("Incident creation response: " + responseBody + " Status: " + httpStatus);
}
4. Test and Validate
Run your Script Include or Business Rule on the source instance to test the incident creation process. Verify that the incident appears in the target instance with the expected details.
5. Error Handling and Logging
Implement error handling in your script to manage potential issues like authentication failures or network errors.
Example Error Handling:
try {
var response = request.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
if (httpStatus === 201) {
gs.info("Incident successfully created: " + responseBody);
}
else {
gs.error("Failed to create incident. Status: " + httpStatus + " Response: " + responseBody);
}
}
catch (e)
{ gs.error("Error creating incident: " + e.message);
}
This guide provides a comprehensive approach to creating incidents in ServiceNow across instances using REST API. Adjust the script and API details according to your specific requirements and instances.
Note: This is not production code, only use it as a guide to achieve the desired functionality.
I have created this demo, that will allow you to visualize how integrations are done with ServiceNow
`
Please mark as helpful if you find the solution lucrative
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2024 09:57 PM
Integrating ServiceNow instances is essential for organizations that manage multiple platforms or work with external partners to streamline processes and ensure seamless communication. One of the most common integration needs is creating an incident on one instance and automatically syncing it to another. In this article, we’ll walk you through the five key steps to create an incident from one ServiceNow instance to another, ensuring efficient data sharing and process automation. By following these steps, you’ll be able to reduce manual effort, minimize errors, and improve collaboration between instances. Whether you're managing internal workflows across different teams or working with external clients, this guide will provide the roadmap to setting up smooth incident creation and synchronization between ServiceNow instances.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2024 09:57 PM
Integrating ServiceNow instances is essential for organizations that manage multiple platforms or work with external partners to streamline processes and ensure seamless communication. One of the most common integration needs is creating an incident on one instance and automatically syncing it to another. In this article, we’ll walk you through the five key steps to create an incident from one ServiceNow instance to another, ensuring efficient data sharing and process automation. By following these steps, you’ll be able to reduce manual effort, minimize errors, and improve collaboration between instances. Whether you're managing internal workflows across different teams or working with external clients, this guide will provide the roadmap to setting up smooth incident creation and synchronization between ServiceNow instances.