Skip to content

Instantly share code, notes, and snippets.

@thisnameissoclever
Last active January 23, 2022 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save thisnameissoclever/a45c8779869ea69bed3e6d6c7334815a to your computer and use it in GitHub Desktop.
Save thisnameissoclever/a45c8779869ea69bed3e6d6c7334815a to your computer and use it in GitHub Desktop.
Get a ServiceNow attachment file's contents as a string (Global)
var tableName = 'incident';
var recordID = '755d52b137b0b30090b68cf6c3990e6f';
gs.print(getAttachmentContentsAsString(tableName, recordID));
function getAttachmentContentsAsString(tableName, recordID) {
//Declare a new instance of GlideSysAttachment.
var gsa = new GlideSysAttachment();
//Get the raw bytes in the file
var bytesInFile = gsa.getBytes(tableName, recordID);
//Convert that jive into a string using Java/Rhino.
var dataAsString = Packages.java.lang.String(bytesInFile);
//Re-convert to a string in Javascript, cause we don't trust Rhino.
dataAsString = String(dataAsString);
return dataAsString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment