Skip to content

Instantly share code, notes, and snippets.

@jmbauguess
jmbauguess / ChangeCIValidation.js
Last active December 4, 2015 19:02
Handles validation of template strings so users cannot submit/save bad templates
/**
* @description Validates that a change request's CI is a valid type based on change type
* @type {Class}
*/
var ChangeCIValidation = Class.create();
ChangeCIValidation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
/**
* @description Validates that a CI is the appropriate class
* @param {String} ci The sys_id of a CI
* @param {String} type A change type
@jmbauguess
jmbauguess / UpdateChangeTaskHandler.js
Created December 4, 2015 16:46
An updated version of ChangeTasker, which handles dates and times
var ct = new ChangeTasker(current),
cm = new ChangeManagementUtil();
if (current.isNewRecord()) {
ct.run();
}
if (ct.dateFieldChanges(current)) {
ct.updateDueDatesOnTasks();
}
if (current.approval.changesTo("approved")) {
ct.runOnApproval();
@jmbauguess
jmbauguess / ChangeTaskHandler.js
Created December 4, 2015 16:43
Creates Change Tasks Dynamically
var ct = new ChangeTasker(current),
cm = new ChangeManagementUtil();
if (ct.isNonInfrastructureCreated()) {
ct.runOnNewChange();
}
if (ct.isInfrastructureScheduled(current.type, current.u_life_cycle_status.changesTo("Scheduled"))) {
ct.runOnScheduled();
}
if (current.cmdb_ci.changes()) {
ct.runOnUpdate();
@jmbauguess
jmbauguess / LeftNavClassCreator.js
Created November 23, 2015 20:21
Creates page object for the LeftNav in ServiceNow
var LeftNavClassCreator = Class.create();
LeftNavClassCreator.prototype = {
HEADERS : {
'java' : 'import org.openqa.selenium.*;\nimport org.junit.*;\n'+
'import org.openqa.selenium.support.*;\nimport com.company.BaseTest;\n\n\n' +
'public class LeftNav extends BaseTest {\n',
'python' : 'class LeftNav : \n',
'ruby' : 'class LeftNav \n',
'csharp' : 'public class LeftNav \n{\n',
'javascript' : 'var LeftNav = {\n',
@jmbauguess
jmbauguess / CopyARequest.js
Last active August 25, 2022 09:30
Back end functionality to copy variables from one requested item to another
/**
* @description Allows users to copy a requested item on the form
* @extends {AbstractAjaxProcessor}
* @type {Class}
*/
var CopyARequest = Class.create();
CopyARequest.prototype = Object.extendsObject(AbstractAjaxProcessor, {
/**
* @description ServiceNow's ArrayUtil
* @type {ArrayUtil}
@jmbauguess
jmbauguess / ApproveAhead.js
Last active September 21, 2015 19:06
Checks to see if a user has already had a chance to approve a record
/**
* @description Looks at other approvals to determine if one needs to be generated
* @type {Class}
*/
var ApproveAhead = Class.create();
ApproveAhead.prototype = {
/**
* @description The name of the approval table
* @type {String}
*/
@jmbauguess
jmbauguess / EncodedQueryReversal.js
Created September 14, 2015 17:53
A script include to reverse the conditions of an encoded query
/**
* @description Reverses an encoded query to provide the oppposite of what it would normally provide
* @namespace
* @type {Class}
*/
var EncodedQueryReversal = Class.create();
EncodedQueryReversal.prototype = {
/**
* @description Contains objects of conditions and what to replace them with
* @type {Array}
@jmbauguess
jmbauguess / ApprovalEventsHandler.js
Last active September 1, 2015 02:20
Refactoring the Approval Events (task) Business Rule into a script include
/**
* @description Determines what event to use when the approval state changes on a task record
* @namespace
* @type {Class}
*/
var ApprovalEventsHandler = Class.create();
ApprovalEventsHandler.prototype = {
/**
* @description Cancelled state value
* @type {String}
/**
* @description Searches for email notifications based on certain criteria
* @namespace
* @type {Class}
*/
var NotificationsTester = Class.create();
NotificationsTester.prototype = {
/**
* @description The name of the email table
* @type {String}
@jmbauguess
jmbauguess / EventTester.js
Last active November 20, 2018 11:17
Allows unit testing of Events
/**
* @description Allows unit testing of Events
* @namespace
* @example
* //Create an incident, update the state, then ensure the incident.state.changed event was fired
* var incident = new GlideRecord('incident');
* if (incident.get(sys_id)) {
* incident.state = 2;
* incident.update();
* }