Decode files and attach in ritm record

jobin1
Tera Expert

Hi All 
i am getting encoded base64 file content(image,pdf,excel etc) via payload in scripted rest resource and I need to decode the file attachment and set these attachments in RITM12345678  how this can be achieved? any simple working solution for this? 

3 REPLIES 3

Peter Bodelier
Giga Sage

Hi @jobin1,

 

Take a look at this article, it should help you out.

Generate Attachments in ServiceNow via REST | John Andersen (john-james-andersen.com)


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Hi Peter
I need the script for decoding and attaching to the respective RITM. Rest all we already have.

Manoj89
Giga Sage

Hi Jobin,

 

Can try something like this

 

var r = new GlideRecord('incident');
r.get('a53a72bb471d3d10220e7f61e36d431b'); //sys_id of the task

var attachment = new GlideSysAttachment();

var fileName = 'maria.jpg';
var contentType = 'image/jpeg';
var be = ${base64EncodedString};
var DecodedBytes = GlideStringUtil.base64DecodeAsBytes(be);

attachment.write(r, fileName, contentType, DecodedBytes)

Source: writeBase64 function of GlideSysAttachment class d... - ServiceNow Community