Reading attachments using GlideSysAttachment getContent() method

craig_granier
Giga Contributor

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);

9 REPLIES 9

craig_granier
Giga Contributor

bump.


paulwoolcock
Kilo Contributor

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?


randallschumm
Kilo Contributor

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.


Has anyone raised /hi INT for this? What was an answer?