Is there a workaround for GlideSysAttachment().getBytes() iam getting an issue beacuse of the Maximam size 5 mb/

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2018 06:18 AM
GlideSysAttachment().getBytes() is returning zero beacuse the size of attachment is more than 5 mb. I have tried to replace the getBytes() function with getContent() and getContentBase64 functions but it is returning as undefined.Is there any other workaround to overcome this issue?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2018 06:31 AM
Can you help me understand what it is you are trying to do?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2018 11:21 PM
Hi Chuck,
Here whenever a new attachment is added to a ticket i want to send an outbound to a third party tool including this attachment content.So here i am using the getBytes method to get a binary data array of that attachment. After that i am encoding that array and i am sending the content to 3 rd party tool.
Its working fine for attachment less than 5MB. But if the the size is more than 5MB getBytes() function is returning as zero.
var grSysAtt = new GlideRecord('sys_attachment');
grSysAtt.addQuery('table_sys_id', 'sys_id');
grSysAtt.query();
while (grSysAtt.next())
{
var sa = new GlideSysAttachment();
var binData = sa.getBytes(grSysAtt);
var b64Util = new GlideBase64();
var encData = b64Util.encodeToChar(binData,false);
var str = new Packages.java.lang.String(encData);
}
Here str is returning null if attachment size is more than 5MB.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2018 01:38 AM
I've seen this myself, I believe it is due to the fact that there is a maximum character count for a string and the system is avoiding an exception at that level (if you're converting to base 64 the length will increase as well).
If you really need to get the entire attachment, you can use the InputStream instead and get an output line by line. This avoids the 5MB limit by splitting the attachment into parts. You'll still face issues if you try to piece the string back together, but this way you'll be able to send the attachment to the other system split across multiple transactions.
See
https://developer.servicenow.com/app.do#!/api_doc?v=istanbul&id=r_SGSA-getContentStream_S
https://developer.servicenow.com/app.do#!/api_doc?v=istanbul&id=c_GlideScriptableInpStrmScopedAPI
https://developer.servicenow.com/app.do#!/api_doc?v=istanbul&id=c_GlideTextReaderScopedAPI
Example from developer portal:
var is = new GlideSysAttachment().getContentStream(attachmentSysId);
var reader = new GlideTextReader(is);
var ln= ' ';
while((ln = reader.readLine()) != null) {
gs.info(ln);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2024 05:16 AM
This will still fail once the string reaches around 16 million length (32MB since each char is 2 bytes).