how to copy attachments in incident from one instance to another instance via rest integration

dskollar
Kilo Explorer

how to copy attachments in incident from one instance to another instance via rest integration

6 REPLIES 6

Brian Lancaster
Tera Sage

There is an attachment reset api.

AbhishekGardade
Giga Sage

REST has an attachment API that can make this a bit easier.

Attachment API

and also please refer these below links might be helpful for you.

Copying attachment from one instance to another 

Copying attachment from one instance to another+

Please mark as Correct Answer and Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies

Thank you,
Abhishek Gardade

Chavan AP
Kilo Sage

Hi Buddy,

 

Write the below code in BR to send attachment from yours instance (source) to another instance (target):

Prerequisite : 1.must create a Rest message

2.create a BR on respective table, in this caste it an Incident

 

(function executeRule(current, previous /*null when async*/) {

try { 
	
	var sa = new GlideRecord('sys_attachment');
	sa.addQuery('table_name', 'incident');
	sa.addQuery('table_sys_id', current.sys_id);
    sa.query();	
while (sa.next()) {

				
				var glide = new GlideSysAttachment();
				var binData = glide.getBytes(sa);
				var payload = GlideStringUtil.base64Encode(binData);
				var file_name = sa.getValue('file_name');
				var content_type = sa.getValue('content_type');
 
 var r = new sn_ws.RESTMessageV2('Outbound_name', 'postAttachment');
r.setRequestHeader("Content-Type", "application/json"); //This is necessary in order to make use of 'Outbound HTTP Requests' logging. Without it, the outbound request body is not recorded in the log.

r.setStringParameterNoEscape('target_reference', current.u_client_ref);
r.setStringParameterNoEscape('target_number', current.number);
r.setStringParameterNoEscape('target_payload', payload);
r.setStringParameterNoEscape('target_file_name', file_name);
r.setStringParameterNoEscape('target_content_type', content_type);

var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
 
gs.log('XXXX attachment ' + count + ' request body: ' + current.number + ': ' + r.getRequestBody());
gs.log('XXXX attachment ' + count + 'responseBody: ' + current.number + ': ' + responseBody);
gs.log('XXXX attachment ' + count + 'httpStatus : ' + current.number + ': ' + httpStatus); 
 

} //end looping through the attachments that need to be sent.

}
catch(ex) {
 var message = ex.getMessage();
 gs.log('XXXX ERROR in Send Attachments: ' + message);
}

})(current, previous);


 

Do mark it as correct answer and also mark it helpful if this resolves your query!!

 

regards,

Ajay

 

Glad I could help! If this solved your issue, please mark it as ✅ Helpful and ✅ Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****