Reading attachments using GlideSysAttachment getContent() method
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2016 05:52 AM
Hi all,
Has anyone had any success w/ using the getContent() method of the GlideSysAttachment object? (API ref) I'm trying to read a list of CI names from a text file and associated those CIs w/ the change the attachment is attached to. I've never used this object/method before and in writing a test script to process an attachment, nothing seems to be working, at least not as I understand how it should work according to the doc. The addInfoMessage that prints out content only prints out a null object reference. Thanks for any help.
My code:
//var sa = new GlideSysAttachment();
if (current.hasAttachments()) {
gs.addInfoMessage('Has Attachments.');
var gr = GlideRecord('sys_attachment');
gr.addQuery('sys_id', 'bf87d687db89eac0f96b7890cf961951');
gr.query();
if (gr.next()) {
gs.addInfoMessage('Found Attachment.');
//process attachment
var ga = GlideSysAttachment();
var content = ga.getContent(gr);
gs.addInfoMessage(content);
} else {
gs.addInfoMessage('Did not find attachment.');
}
}
action.setRedirectURL(current);
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2017 06:58 AM
I have found that in the global scope, then you will "undefined" for the getContent method. If you use the same code in a scoped app then you get results that you expect instead of "undefined". The link here states that you may get unexpected results in you use the object in the global scope;
https://developer.servicenow.com/app.do#!/api_doc?v=helsinki&id=r_SGSA-GlideSysAttachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2017 08:58 AM
I was getting the same "is not defined" but i found out that i was using the glidesysattachment in a client script. It does not work there, once i put in the business rule it worked.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2019 04:06 AM
I'm not seeing any warning about needing to be used in a scoped app: https://developer.servicenow.com/app.do#!/api_doc?v=madrid&id=r_SGSA-GlideSysAttachment

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2019 04:31 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2022 08:14 AM
Super helpful--thank you!