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
/** | |
* Does the work on each loop. | |
* @param {Number} [limit=10] - The number of records to process per loop. | |
* @param {Number} [currentNumber=0] - The number of records that have been processed so far, by all previous loops. | |
*/ | |
function eventWrapper(limit, currentNumber) { | |
var EVENT_NAME = 'EVENT.NAME.HERE'; //todo: Update this to the name of the event you've created. | |
var TABLE_NAME = 'TABLE_NAME_HERE'; //todo: Update this to the name of the table containing the records you're processing | |
var QUERY = 'some_query=here'; //todo: Put your query here |
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. |
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 recordTable = 'incident'; | |
var idOfRecord = '755d52b137b0b30090b68cf6c3990e6f'; | |
var grAttachment = getAttachmentRecord(recordTable, idOfRecord, 'example text doc.txt', true); | |
var gsaTextFile = new GlideSysAttachment(); | |
var strContents = gsaTextFile.getContent(grAttachment); //ONLY worked in non-global scope | |
gs.info(strContents); | |
/** |
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 sysIDOfRecord = '755d52b137b0b30090b68cf6c3990e6f'; | |
var fileNameSansExtension = 'example text doc'; //Full file name: example text doc.txt | |
var grRecordWithAttachment = new GlideRecord(tableName); | |
grRecordWithAttachment.get(sysIDOfRecord); | |
var gsa = new GlideSysAttachment(); | |
//ONLY works in global | |
var textVal = gsa.get(grRecordWithAttachment, fileNameSansExtension); |
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 recordTable = 'incident'; | |
var idOfRecord = '755d52b137b0b30090b68cf6c3990e6f'; | |
var grAttachment = getAttachmentRecord(recordTable, idOfRecord, 'example text doc.txt', true); | |
if (grAttachment !== false) { | |
var attachmentStream = new GlideSysAttachment().getContentStream( | |
grAttachment.getValue('sys_id') | |
); | |
var gDigest = new GlideDigest(); | |
var base64MD5 = gDigest.getMD5Base64FromInputStream(attachmentStream); //Scope only | |
gs.info(base64MD5); |
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 grAttachment = new GlideRecord('sys_attachment'); //the table where attachment metadata is stored | |
grAttachment.get('0003ea666f015600623008efae3ee4f7'); //sys_id of a record in the sys_attachment table | |
var md5HashSum = calculateMD5Hash(grAttachment); | |
function calculateMD5Hash(attachmentGR) { | |
var attachmentInputStream = GlideSysAttachmentInputStream(attachmentGR.sys_id + ''); | |
var chksum = (new GlideChecksum()).calculateMD5CheckSum(attachmentInputStream); | |
gs.print(chksum); | |
} |
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
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) { | |
var body = request.body; | |
var streamBody = body.dataStream; | |
var stringBody = getBodyText(streamBody); | |
gs.log('Message body: ' + stringBody); | |
function getBodyText(streamBody) { |
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
copySpecificAttachment(donorTable, donorID, recipientTable, recipientID, fileName); | |
function copySpecificAttachment(donorTable, donorID, recipientTable, recipientID, fileName) { | |
var donorAttSysID, | |
grNewAttachment, | |
linkToNewRecord, | |
attDataRecord, | |
newDocRecord, | |
grAttachment = new GlideRecord('sys_attachment'); | |
grAttachment.addQuery('table_name', donorTable); |
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
//Note: Read from innermost, outward | |
getAllUrlParams( | |
decodeURIComponent( | |
getAllUrlParams( //Get all URL params. Since SN re-encodes everything it passes into page processors like "nav_to.do" for example, this will have one key-val pair. | |
(this.location.href ? this.location.href : window.location.href) //The document URL. Should work for SP, and desktop view. | |
)['uri'] | |
) | |
); | |
var yourParamValue = getAllUrlParams(this.location.href)['YOUR_PARAM_NAME']; |
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 exampleObj = { | |
"name": "Tim", | |
"age": 31, | |
"groovy": true, | |
"dogs": [ | |
{ | |
"name": "Ezri", | |
"age": 1 | |
}, | |
{ |