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'm having the problem you had two years ago. Do you happen to remember where you put the source like the URL for the instance for incident and the instance for change request? something like www.change.servicenow.com and www.incident.servicenow.com. To let the system know which instance's incident and change request to act on? It seems like your answer is missing a bit


Hi Collfit,

I know i am responding to this question after a long time and i apologize for it, but to answer the question, the links of the target instance was used in the outbound SOAP message and then i have called it in the script include.

Once again apologies for not responding earlier

Hi collfit, 

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

Sri56
Tera Contributor

Hi Dinesh,

 

Can you please specify where we need to do this modifications?

Is it on SoapAttachment script include?

 

Thanks,

Sri

Hi Sri,

Apologies for my delayed response, nope, the code mentioned in the solution is the actual code that i have used to send the attachment from one instance to another. It was written in my custom script include.