Decode files and attach in ritm record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 07:59 AM
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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 08:06 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 08:15 AM
Hi Peter
I need the script for decoding and attaching to the respective RITM. Rest all we already have.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 10:18 AM
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