How to get the content of an Attachment?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2017 06:03 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2017 07:26 AM
Hi Peter,
Yes that should suffice. But it all depends on how the third party accepts attachment. As I said earlier usually when we use SOAP and send/receive attachment data it is in base64 format.
Just check with the requirement.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2017 07:40 AM
Hi Peter,
Could you also mark the answer as correct and hit like? This helps in closing the thread for the question. Thanks in advance.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2017 07:43 AM
I know, but the button has gone missing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2017 01:21 AM
Hi Peter,
As you mentioned in your earlier comment that the button has gone missing. Following is the link which can help you to mark a discussion as correct/answered.
Please mark the answer as correct and hit like. Thanks in advance.
How to mark a discussion as answered in SNOW community?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2017 03:12 AM
The button is not there because this is not a question, but a discussion.