PrashantLearnIT
Tera Sage

Did you know getBytes function in attachment script has some size limits?

getBytes function is used in attachments scripts to get base64 data. This function has a payload limit of 4MB which means attachments larger than 4MB cannot be transferred. Below scripts can be used as an alternative.

Script where getBytes function is used:

var sa = new GlideSysAttachment();

var binData = sa.getBytes(attachmentRecordObject);

var base64 = GlideStringUtil().base64Encode(binData); // Limit of 4MB

 

Alternative  - Calling script from non-global scope:

var sa = new GlideSysAttachment();

sa.getContent(attachmentRecordObject);

var base64 = sa.getContentBase64(attachmentRecordObject);

 

Alternative  - Calling script from global scope: 

var gsa = GlideSysAttachmentInputStream(AttachmentRecordObject.sys_id.toString());

var baos = new Packages.java.io.ByteArrayOutputStream();

gsa.writeTo(baos);

baos.close();

var base64 = GlideStringUtil.base64Encode(baos.toByteArray());

 

If my content helped you in anyway, please mark this content as BOOKMARK, SUBSCRIBE & HELPFUL

 

Best Regards,

Prashant Kumar (LearnIT)

 

YouTube Channel LearnIT: https://www.youtube.com/@learnitwithprashant

Blog LearnIT: https://medium.com/@LearnITbyPrashant

Prashant Kumar LinkedIn: https://www.linkedin.com/in/learnitbyprashant/

ServiceNow Community Prashant Kumar - https://www.servicenow.com/community/user/viewprofilepage/user-id/19635

1 Comment