Last active
January 23, 2022 00:13
-
-
Save thisnameissoclever/a45c8779869ea69bed3e6d6c7334815a to your computer and use it in GitHub Desktop.
Get a ServiceNow attachment file's contents as a string (Global)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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