How to get the content of an Attachment?

peterraeves
Mega Guru

I uploaded a simple text file to an Incident and want to retrieve the content through javascript to pass it over an external rest call.

I'm using the following code as explained by the docs, but they do not seem to be working.

var att = new GlideRecord('sys_attachment');

att.get('file_name', 'Test.txt');

gs.print(att.getDisplayValue() + '***' + att.size_bytes + '***' + att.content_type);

var sa = new GlideSysAttachment();

var content64 = sa.getContentBase64(att);

gs.print(content64);

var content = sa.getContent(att);

gs.print(content);

My output is:

*** Script: Test.txt***11***text/plain

*** Script: undefined

*** Script: undefined

Additionally, the documentation stated that only 5MB is returned through the getContent functions. What if the document is larger than that?

16 REPLIES 16

@ANINDYA SUNDAR 

Please post a new question and tag me there as this is an old thread.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader