Receiving Attachment from other Servicenow instance through REST APi
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2024 10:37 AM
Hi Team,
How to receive attachments from other Servicenow instance through REST method.
We are transferring incident data from other SN instance to our side. I have configured for fields data and wanted to know how attachments also can be retrieved. Below is code I have used:
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var body = request.body.dataString;
var payload = JSON.parse(body);
// Get data from payload
var sysID = payload.sys_id;
var state = payload.state;
var comments = payload.addtional_comments;
var priority = payload.priority;
var correlationID = payload.sys_id;
var short1 = payload.short_description;
var desc1 = payload.description;
var custnum = payload.number;
var importTable = new GlideRecord('sn_customerservice_case');
// Check if a record with the same number exists
importTable.addQuery("u_customer_ticket", custnum);
importTable.query();
if (!importTable.next()) {
// No existing record found, create a new one
importTable.initialize();
// Set data to new record
importTable.state = state;
importTable.addtional_comments = comments;
importTable.priority = priority;
importTable.correlation_id = correlationID;
importTable.short_description = short1;
importTable.description = desc1;
importTable.u_customer_ticket = custnum;
// Insert new record
importTable.insert();
} else {
// Record found, update it
importTable.state = state;
importTable.additional_comments = comments;
importTable.priority = priority;
importTable.correlation_id = correlationID;
importTable.short_description = short1;
importTable.description = desc1;
importTable.u_customer_ticket = custnum;
// Update existing record
importTable.update();
}
var responseBody = {
caseNumber: importTable.number,
message: 'Case processed successfully'
// Add more fields as needed
};
// Send response
response.setStatus(200);
response.setContentType('application/json');
response.setBody(responseBody);
})(request, response);
Kindly help with above
Thank you
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2024 10:55 AM
Hello @maneesh3 ,
You can follow the below article to know more about, how to handle attachments in ServiceNow from REST API.
Please mark my answer as accepted solution and give thumbs up, if it helps you.