
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2016 08:25 PM
I have been bashing my head against this and can't believe I'm the only one to run into this. Hope it's just I'm doing something wrong.
To test problem I created a simple form with an encoded data field and a UI action:
var sa = new GlideSysAttachment();
var binData = gs.base64Decode(current.encoded_contents);
sa.write(current, "Test.pdf", "application/pdf",binData);
action.setRedirectURL(current);
You would think this works... NOPE. I get an attachment. It thinks it's PDF and it's about 20% larger than the original. All the ascii text is correct in it but the binary is messed up.
I've tested the encode/decode -> mid server (did it in java) -> server... All working but this write function.
Developer site has only the description of the call and it's function. No examples. From my "working with it' it does take the text and write it to the attachment..
Any help/insight would be greatly appreciated!
Just tried another obvious thing. Added a PDF as an attachment to this record and ran the following UI Action:
var gr = new GlideRecord("sys_attachment");
gr.addQuery( "table_name", "=", "x_uxs_test_error_table");
gr.addQuery( "table_sys_id", "=" , current.sys_id + "");
gr.query();
if (gr.next()) {
gs.addInfoMessage("Getting attachment");
var sa = new GlideSysAttachment();
var contents= sa.getContentBase64(gr);
gs.addInfoMessage("Got Contents: ");
current.encoded_contents = contents;
current.update();
sa.write(current, "newOrig.pdf","application/pdf", gs.base64Decode(contents));
}
action.setRedirectURL(current);
I get the infomessages. I get the data in base64 encoded on the form. I get a second "newOrig.pdf" and it's wrong!
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2016 02:40 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2016 02:40 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2016 01:35 PM
Hi, Reed. Has there been any update on this from ServiceNow? I just ran into the same issue, and to say the least, it makes things difficult if you need to deal with binary attachments in scoped apps.
Thanks...
-- Bill

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2016 01:58 PM
Call me on my cell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2016 03:20 AM
Hi Reed,
Thank you for your post! I am running into the same issue although we are not in a scope app(not sure if it makes a difference). I am able to attach to the record what appears to be a pdf but when I try to open it it can't recognize the file. Did you find any work around this? The version I work in is Fuji. I will greatly appreciate your time,
--Stef