ServiceNow to ServiceNow integration using import set API.

niveditakumari
Mega Sage

Hi All, 

 

Can anyone please tell me step by step setup that how I can achieve ServiceNow to ServiceNow integration using import set API with coalesce field and transform map script. 

ex- When I create incident in instance A it should create incident in instance B. 

 

Regards, 

Nivedita

 

 

9 REPLIES 9

Voona Rohila
Kilo Patron
Kilo Patron

Hi @niveditakumari 

You can integrate 2 instances using REST or Soap.

Refer below links for detailed steps

https://www.servicenow.com/community/developer-articles/servicenow-to-servicenow-integration-step-by...

https://www.servicenow.com/community/developer-articles/servicenow-to-servicenow-integration-using-r...

https://www.servicenow.com/community/now-platform-blog/servicenow-to-servicenow-integration/ba-p/233...


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Hi @Voona Rohila ,

 

Thank you for your reply. 

I have already explored this link. 

I have to do import set api integration and all link which you have sent that is for table api integration. 

 

Regards, 

Nivedita

 

Hi 

refer below link.

https://developer.servicenow.com/dev.do#!/reference/api/rome/rest/c_ImportSetAPI


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

MD AQUIB KHAN
Giga Guru

Hi,

I guess you need to do using scripted rest API.

Please find the sample script below. You can do similar for update as well.

MDAQUIBKHAN_0-1669198077395.png

 

Scripts:

// for insert 

(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

    var requestBody = request.body;
    var requestdata = requestBody.data;
	var message = "";
	
    var arraygr = new ArrayUtil();
    var obj = null;
    if (requestdata instanceof Array) {
        obj = requestdata[0];
    } else {
        obj = requestdata;
    }
gs.log('REQUESTBODY:' + requestBody);
gs.log('REQUESTDATA :' +requestBody.data);
gs.log('OBJ:' +obj);
gs.log("Number :" + obj.u_number);
gs.log("Number1 :" + obj.u_state);

if(obj != null){
	gs.log('ShortDescription :' + obj.u_short_description);
	gs.log('Description :' + obj.u_description);
	gs.log('Contact_type :' + obj.u_contact_type);
	gs.log('Assignemnt Group :' + obj.assignment_group);
	gs.log('Assignemnt Group1 :' + obj.getDisplayValue('assignment_group'));
}
	// create the incident :
 var gr = new GlideRecord('incident'); // modify your table accordingly
 gr.initialize();

 gr.short_description = obj.u_short_description;
 gr.description = obj.u_description;
 gr.contact_type = obj.u_contact_type;
 gr.state = obj.U_state;
 gr.category = obj.u_category;
 gr.subcategory = obj.u_subcategory;
gr.assignment_group= obj.assignment_group;
 gr.caller_id = obj.u_caller_id;
 gr.work_notes = obj.u_work_notes;
 gr.correlation_id = obj.u_number;
 gr.insert();

 return {
     "INCNumber": gr.number, // return the number .
	 "Message" : message
 };
})(request, response);

// For Update:
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

    // implement resource here
    var requestBody = request.body;
    var requestData = requestBody.data;
    var obj = null;

    var arraygr = new ArrayUtil();

    if (requestData instanceof arraygr) {

        obj = requestData[0];
		gs.log('obj:' + obj);
    } else {
        obj = requestData;
    }
  
    var objnumber = obj.u_number;
    if (obj != null) {
       // gs.log('Number_Update' + );
         //gs.log('Sysid' +  obj.sysid);
        //gs.log('Correlation ID:' + obj.correlation_id);
    }
	try {
		gs.log('Enter try');
    var gr = new GlideRecord('incident');
   // gr.addQuery('sys_id',  obj.sysid);
    gr.addQuery('correlation_id', objnumber);
	gs.log('object' + objnumber);
    gr.query();
    if(gr.next()) {
		gs.log('Enter_update');
		gs.log('number_update:' + gr.number);
        gr.state = obj.u_state;
        gr.short_description = obj.u_short_description;
        gr.description = obj.u_description;
        gr.work_notes = obj.u_work_notes;
        gr.close_code = obj.u_close_code;
        gr.close_notes = obj.u_close_notes;
		//gr.correlation_id = gr.number;
        gr.update();
		return {
		
        "Number":gr.number
		
         
    };
			
	}
		else{
			return {"Message " : "Incident is not updated"};
		}
		

	}
	catch(error){}
   
	

})(request, response);