How to get the base 64 encoding of a servicenow attachment

Debanjan3
Kilo Explorer

Hi All,

 

I am trying to send an attachment via web service and trying to use attachment Creator message for that.So when we need to give the base64 encoding of an attachment,

how to get that ?

 

regards,

Debanjan

2 REPLIES 2

poyntzj
Kilo Sage

This is the code I have in one of our Script Includes for WSDL


It is called from a BR that has determined if the attachment needs to be sent or not



s = new SOAPMessage('xxxxx', 'update');


var sa = '';


var binData = '';


var encData = '';


gr = new GlideRecord('sys_attachment');


gr.addQuery('sys_id',this.asys_id);


gr.query();


if (gr.next()) {


      s.setStringParameter('filename',gr.file_name);


      s.setStringParameter('comment', 'Adding Attachment : ' + gr.file_name);


      s.setStringParameter('type',gr.content_type);


      sa = new GlideSysAttachment();  


      binData =   sa.getBytes(gr);  


      s.setStringParameter('encData', GlideStringUtil.base64Encode(binData));


}



Inactive_Use603
Kilo Expert

this might help to understand the approach of sending files via Web Service ServiceNow Attachment Files via Web Service - YouTube