Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Copying attachment from one instance to another

dinesh91n
Tera Expert

Hi guys, i have task to copy an attachment from an incident, from one instance to a change request in another instance using soap web services. Can anyone help me on this.

1 ACCEPTED SOLUTION

dinesh91n
Tera Expert

hi guys i found the solution


used these two to finish the code GlideStringUtils, GlideSysAttachment


revised code:


var StringUtil = new GlideStringUtil();


  var attachments = new GlideSysAttachment();


  var fileName, contentType;


  var gR = new GlideRecord('sys_attachment');


  gR.addEncodedQuery('table_name=incident^table_sys_id='+current.sys_id);


  gR.query();


  while(gR.next()){


  try {


  var binData =   attachments.getBytes(gR);


  var encData =   StringUtil.base64Encode(binData);


  gs.log('XML Respons for payload='+encData);


  var s = new sn_ws.SOAPMessageV2('Copy attachments', 'insert');


  s.setStringParameter('source', 'change_request:'+current.u_change_sysid);


  s.setStringParameter('payload', encData);


  s.setStringParameter('topic', 'AttachmentCreator');


  s.setStringParameter('agent', 'AttachmentCreator');


  s.setStringParameter('name', gR.file_name+':'+gR.content_type);


  var response = s.execute();


  var responseBody = response.getBody();


  var status = response.getStatusCode();


  }


  catch(ex) {


  var message = ex.getMessage();


  }


  }


View solution in original post

11 REPLIES 11

Hi Dinesh, 

I got the same requirement as you performed few years back, could you please help me with SOAP MESSAGE.

like how do u create SOAP MESSAGE and what are the steps you followed.

 

Thanks & Regards,

Aswartha Reddy

Hello Dinesh,

 

Same thing I want to apply change request. Is it possible the same code