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

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


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.


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

And here's how I use it in the Global Scope:

 

find_real_file.png

 

getBytes() can be used in global scope.

Super helpful--thank you!