writeBase64 function of GlideSysAttachment class doesn't work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 01:47 PM
Try to use writeBase64 function of GlideSysAttachment class to save a binary file (base64 string) as an attachment of an sc_req_item record.
I tried the following:
var base64String = "...."
var attachement = new GlideSysAttachment();
var gr = new GlideRecord("sc_req_item");
// find the corresponding record
var attachment_sys_id = attachement.writeBase64(gr, "test.pdf", "application/pdf", base64String );
gs.log("system attchment id:" + attachment_sys_id);
attachment_sys_id is "undefined" and no attachment was created and attached.
However, if I change writeBase64 to write, an attachment was created and attached, attachment sys id was returned, but the attachment was not the correct format.
Any idea?
- Labels:
-
Scoped App Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 02:29 PM
Hello,
The example code you're using never specifies which Request Item to attach this file to.
Try something like this:
var base64String = "...."
var attachment = new GlideSysAttachment();
var gr = new GlideRecord("sc_req_item");
gr.get('aeed229047801200e0ef563dbb9a71c2'); // Replace this with desired sys_id
// find the corresponding record
var attachment_sys_id = attachment.writeBase64(gr, "test.pdf", "application/pdf", base64String );
gs.log("system attachment id:" + attachment_sys_id);
Replace the sys_id with the sys_id of the record you want to add this attachment to.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 02:36 PM
Thank you Josh!
We had a specific query which got us a gliderecord. I just didn't show all the code there.
In my example, if i use write instead of writeBase64, the file was attached to the request.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 02:38 PM
Our SN instance is Istanbul Patch6, not sure if it is a SN version issue

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 02:46 PM
Ahh, makes sense. I'd check a few things:
1) Try hard coding a sys_id when looking up the sc_req_item to make sure there aren't issues with the query/iteration logic.
2) Check log files - are there any messages after you attempt the insert?
3) Check the sys_attachment table - does anything show up here after the call to writeBase64()?