Alternative of attachment functions in global scope
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2019 06:22 AM
May i know what is the alternative of getcontent , getcontentbase64, writecontentbase64 in global scope.
These functions of glidesysattachment class work fine in scoped app ony. Wondering if we have similar functions for global scope. I need to read/write attachments using scripts.
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2019 07:52 AM
You can use new GlideSysAttachment().getBytes method to get the content from GlideRecord of "sys_attachment" table. You can convert the bytes to Base64 using GlideStringUtil.base64Encode. If the attachment is a text file then you can use Packages.java.lang.String to convert bytes to string.
For example, I added to an incident with sys_id="e128e85adb4d230095a810825b961960" HTML file test.html. I can use the following code to read the attachment:
var attachmentGR = new GlideRecord("sys_attachment");
attachmentGR.addQuery("file_name", "test.html");
attachmentGR.addQuery("table_name", "incident");
attachmentGR.addQuery("table_sys_id", "e128e85adb4d230095a810825b961960");
attachmentGR.query();
if (attachmentGR.next()) {
var bytesContent = new GlideSysAttachment().getBytes(attachmentGR);
var base64ImageStr = GlideStringUtil.base64Encode(bytesContent);
gs.print("base64ImageStr=" + base64ImageStr);
var strData = Packages.java.lang.String(bytesContent);
gs.print("strData=" + strData);
}
P.S. See Script Includes GeneralFormAPI and SoapAttachments for code examples.