- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2019 01:55 PM
I am trying to add base64 encoded files (images, etc.) as attachments onto an HR Case (scoped) via integration with a Scripted REST API. (I am unable to use the REST Attachment API as the system sending the data is unable to provide the target record sys_id, and it also needs to include additional attributes to update the target record when it sends the attachment.)
I am able to achieve the task successfully in the Global scope without issue (other than the fact that there is a 25 Mb payload limitation), but the methods I am using in the Global scope (particularly GlideStringUtil.base64DecodeAsBytes()) are not available from the scoped application. Is there a scoped alternative to GlideStringUtil.base64DecodeAsBytes()?
The plain method I utilized in Global scope was:
var data = '<base64 encoded image/file data>';
var attach = new GlideSysAttachment(),
//Decode base64 data
var decodedBytes = GlideStringUtil.base64DecodeAsBytes(data);
//Write attachment associated to target record
var attchID = attach.write(<target_GlideRecord>, <Attachment_Name>, <Attachment_Type>, decodedBytes);
If I try using the AttachmentCreator method, the ECC Queue fails to write the attachment (due to scope permissions) with an error like: "Could not find a record in table '<target_table>' with sys_id '<target_record>'."
I have been unable to pass the work over to a Global script include, as I am unable to pass back the decoded bytes for the actual creation of the attachment.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2019 07:49 PM
Hi Shane,
use following code and it should work; I have tested the same
writeBase64() method accepts base64EncodedData as last parameter and this should work in scoped app;
no need to convert to bytes etc
var data = '<base64 encoded image/file data>';
var attach = new GlideSysAttachment(),
//Write attachment associated to target record
var attchID = attach.writeBase64(<target_GlideRecord>, <Attachment_Name>, <Attachment_Type>, data);
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 07:05 PM
I have tried the "writeBase64" method in scope, unfortunately the attachment is generated using this but the file is corrupted, doesn't work for docx, image etc only works for text.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 07:43 PM
can you post a new thread and tag me there as this is an old thread?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2024 10:46 PM
Sure