logo

NJP

ServiceNow Things to Know 4: getBytes function

Import · Dec 09, 2023 · article

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:

View original source

https://www.servicenow.com/community/developer-blog/servicenow-things-to-know-4-getbytes-function/ba-p/2753864