How to send attachment from instance to another instance.

niveditakumari
Mega Sage

Hi, 

 

How to send attachment from one instance to another instance. When I'm creating incident in one instance it is creating in another instance with having same details and I want to send attachment from one instance to another instance. 

Can anyone please tell how to send attachment from one instance to another instance. 

 

Regards, 

Nivedita 

 

 

1 ACCEPTED SOLUTION

11 REPLIES 11

Sumanth16
Kilo Patron

Hi @niveditakumari ,

 

Check the below links,

There are solutions already available.

 

https://www.servicenow.com/community/developer-forum/copying-attachment-from-one-instance-to-another...

https://www.servicenow.com/community/developer-forum/copying-attachment-from-one-instance-to-another...

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda

Hi @Sumanth16

 

I have already gone through that link that is with soap and I need to achieve it with REST API. 

 

Regards, 

Nivedita 

 

 

Harish KM
Kilo Patron
Kilo Patron

Hi @niveditakumari  is it from servicenow to servicenow? if yes you can use OOB Attachment API like below,

HarishKM_0-1709867410372.png

create rest api and BR on incident table like this

var user = 'aaa';
var password = 'xxx@';
var attachmentRec = new GlideRecord("sys_attachment");
attachmentRec.addQuery('table_name','incident');
attachmentRec.addQuery('table_sys_id',current.table_sys_id);
attachmentRec.query();
gs.log("--> "+attachmentRec.getRowCount());
if (attachmentRec.hasNext()) {
while (attachmentRec.next()) {
var attachmentMessage = new sn_ws.RESTMessageV2();
attachmentMessage.setHttpMethod("post");
attachmentMessage.setBasicAuth(user,password);
attachmentMessage.setEndpoint("https://devxxx.service-now.com/api/now/attachment/file");// other instance end point
attachmentMessage.setQueryParameter("table_name", "incident");
attachmentMessage.setQueryParameter("table_sys_id", attachmentRec.u_test);
attachmentMessage.setQueryParameter("file_name", attachmentRec.file_name);
attachmentMessage.setRequestHeader("Content-Type", attachmentRec.content_type);
attachmentMessage.setRequestHeader("Accept", "application/json");
attachmentMessage.setRequestBodyFromAttachment(attachmentRec.sys_id); // send the attachment as request Body

var response = attachmentMessage.execute();
var responseBody = response.getBody();
gs.log("* responseBody "+ responseBody);
var httpStatus = response.getStatusCode();
gs.log("* atatch "+ httpStatus);

}
}

Regards
Harish

Hi @Harish KM

 

Thank you for your help. 

I have gone through above code and tried to understand but not understood completely. Can we connect? 

Can you please help me to make me understand. 

 

Regards, 

Nivedita 

 

 

Hi @niveditakumari Sure you can DM me. You can also take a look at documentation below

https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/rest/c_AttachmentAPI#attachment...

Regards
Harish