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
08-14-2016 06:45 PM
bump.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2016 12:02 PM
Craig -
This seems to be working for me:
var attachment_sysid = /* some sys_id string */;
var gr = new GlideRecord("sys_attachment");
if (gr.get(attachment_sysid)) {
var ga = new GlideSysAttachment();
gs.debug("content: {0}", ga.getContent(gr));
} else {
gs.debug("Could not find sys_attachment record for sysid {0}", attachment_sysid);
}
Looks like the code you posted is missing some `new` operators, could that be it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2017 10:46 AM
I'm having the same or similar issue in Helsinki that the GlideSysAttachment object I create (using new) doesn't seem to have the getContent method. In the logs it showing this method is undefined. I can't figure out why its not defined.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2017 08:25 AM
Has anyone raised /hi INT for this? What was an answer?