Receiving Attachment from other Servicenow instance through REST APi

maneesh3
Tera Contributor

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

Abhishek_Thakur
Mega Sage

Hello @maneesh3 ,

You can follow the below article to know more about, how to handle attachments in ServiceNow from REST API.

https://www.bing.com/ck/a?!&&p=fd0f5a3bfe3385dbJmltdHM9MTcyNzIyMjQwMCZpZ3VpZD0yMThjMDMwNi1iNjc1LTY0Z...

 

Please mark my answer as accepted solution and give thumbs up, if it helps you.