Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save pchaozhong/3f02bbbea88b43b80b74bbb7e8b127d4 to your computer and use it in GitHub Desktop.

Select an option

Save pchaozhong/3f02bbbea88b43b80b74bbb7e8b127d4 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;
}
@salemsap
Copy link

it convers only text file. is there any way to convert any file format like doc, docx, excel, csv, jpg, gif,pdf,etc..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment