Posting Attachments through Scripted REST API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2024 11:02 AM
We have a requirement where a third part application needs to send an attachment to Service Now and attach it to a record. We cannot use the out of box Attachment API as that requires the Sys Id of the record being updated and they won't have it. So I am building a Scripted Rest API based on the following GlideSysAttachment command.
I have tried to add this sample code from the documentation and updated the sys id of an incident that exists in my instance.
var attachment = new GlideSysAttachment();
var rec = new GlideRecord('incident');
var incidentSysID = 'ab1b30031b04ec101363ff37dc4bcbfc';
rec.get(incidentSysID);
var fileName = 'example.txt';
var contentType = 'text/csv';
var base64Encodedcontent = 'SSBhbSB0ZXh0Lg==';
var agr = attachment.writeBase64(rec, fileName, contentType, base64Encodedcontent);
gs.info('The attachment sys_id is: ' + agr);
When I run this through fix script to test the logic, I get the following message,
GlideTime - unparseable date: invalid function
*** Script: The attachment sys_id is: undefined
And the attachment does not get added. What am I doing wrong? Should this work through a fix script as a test?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 11:36 PM
Maybe you are running it in global scope. This method doesn't seem to be supported in global. Copy/paste it in background script, pick any other scope and run it.