GlideSysAttachment().getBytes() is not working if size of attachment is more than 5 MB?

lvakare
Kilo Contributor

Hi All,

I am using Helsinki and I am facing same Issue When file size is greater than 5 MB showing as 0 bytes.Debugging this, at the line var binData = sa.getBytes(att), binData.length = 0.In ServiceNow community we see similar post(https://community.servicenow.com/thread/195363) which says getBytes() method has a limit of 5MB I tried solution given in the post(https://community.servicenow.com/thread/195363) but it doesn't work.Can any one help in resolving this.

Below is part of script I use:

function sendAttachment(att,counter) {

  gs.log('Export Attachments Script - Send Attachment #'+counter+' - START');

  var bool = false;

  try {

  //Create GlideSysAttachment object

  var sa = new GlideSysAttachment();

//Gets the binary data of the passed attachment

var binData = sa.getBytes(att);

//Encodes the binary to base64

  var encData = GlideStringUtil.base64Encode(binData);

//Prepares a file name a "TABLE_NAME - (commented)TICKET_SYS_ID - SYS_ID - FILE_NAME"

  var file_name = att.table_name + "-" + att.table_sys_id + "-" + att.sys_id + "-" +   sanitizeFileName(att.file_name.toString()).trim();

  //Calls send Request for binary data and generated file name

  sendRequest(encData, file_name);

  //If no exception always return true

  bool = true;

  } catch (Exception) {

  gs.log('Failed sending Attachment to due to Exception: '

  + Exception);

  }

  return bool;

}