Skip to content

Instantly share code, notes, and snippets.

View cmcdevitt's full-sized avatar
🏠
Working from home

Chris McDevitt cmcdevitt

🏠
Working from home
View GitHub Profile
@cmcdevitt
cmcdevitt / timming_functions.js
Created December 16, 2022 19:42
Timing for JavaScript Function / Methods
//Top of Script / Function / Method
var start;
var end;
var dur;
start = new GlideDateTime();
// Function OR Method between start and end
end = new GlideDateTime();
dur = GlideDateTime.subtract(start, end);
@cmcdevitt
cmcdevitt / setClosedAt.js
Last active December 14, 2022 21:12
Change Closed [closed_at] for Testing of VR Auto-Delete
/*
Run in a BackGround Script or a Fix Script
closed_at Type = Date/Time
*/
vit = 'e3ef3a1787fd91102d0b422e0ebb3551';//sys_id of a VIT:: VIT0014433
var gdt = new GlideDateTime("2022-12-14 08:00:01");//Set the time you want here
var vi = new GlideRecord('sn_vul_vulnerable_item');//GlideRecord
vi.get(vit);
vi.setValue('closed_at', gdt);
vi.update();
@cmcdevitt
cmcdevitt / reopen_sir.js
Created December 9, 2022 14:08
Reopen SIR
var SIRUTILS = Class.create();
SIRUTILS.prototype = {
initialize: function() {},
canReopenSIR: function( /*GlideRecord*/ incident) {
/*
Call this in UI Action Condition:
new sn_si.SIRUTILS().canReopenSIR(current)
*/
var hasRole = gs.hasRole('itil'); //pick a better role
@cmcdevitt
cmcdevitt / populate_servey_questions_script.js
Last active November 2, 2022 21:00
Populate Survey Questions via Script ServiceNow
/*
ServiceNow Vulnerability Response Exception Questionnaire
1. 'Assessment Instance Questions' [asmt_assessment_instance_question] table is populated with the Assessment Instance Questions
1.a. Keyfields: Source, Souce Table, Metric, Instance
2. The 'State Change Approval'[sn_vul_change_approval] table is populated with that Approval info AND
2.a Keyfield Questionnair [assessment_instance]
3. You need a way to associate the Assessment Instance Questions back to the triggering event
3.a Example: State Change Apprval KNOWS about the Assessment Instance via the Questionnair [assessment_instance] field
4. You will need to work "backwords" from the Assessment Instance Question table
4.a A Business Rule: "Before - Insert" :: Condition Source[source_id] is <sys_id>
@cmcdevitt
cmcdevitt / client_script_examples.js
Created October 13, 2022 14:59
Client Script Examples
/*
Stop form submission if fields are invalid
UI Type: All
Type: onSubmit
*/
function onSubmit(){
//Get Fields to Test
var valid = g_form.getValue('group_name_available');
//Test Fields
if('false' == valid){
@cmcdevitt
cmcdevitt / reapply_ci_lookup_rules.js
Created October 12, 2022 14:18
Reapply CI Lookup Rules
new sn_sec_cmn.CILookupUtil().updateReapplyFlag();
var ciLookupUtil = new sn_sec_cmn.CILookupUtil();
var utils = new sn_sec_cmn.BackgroundJobUtils();
ciLookupUtil.createBackgroundJob();
var jobGr = utils.getQueuedJob('Reapply CI lookup rules');
gs.info("This is the queued job " + jobGr.number);
try{
var message = ciLookupUtil.getStats();
gs.info("Ci lookup stats" + message);
@cmcdevitt
cmcdevitt / widget_client_script_examples.js
Created October 7, 2022 14:11
Portal Widget Client Script Example
/*
Widget Client Script
I am not a SN Portal person so take this with a grain of salt!
*/
function($scope) {
/* widget controller */
var c = this;
c.config = {
@cmcdevitt
cmcdevitt / scripted_rest_example_basic.js
Created October 4, 2022 15:51
Scripted REST Resource Example - Basic
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
//var util = new global.ChangeRequestAPI();
var requestBody = request.body; //Already parsed from JSON to object
var requestData = requestBody.data;
if (requestData) {
//Get Input Data
var change_request = requestData.u_change_request;//"standard"
//Process Data
@cmcdevitt
cmcdevitt / ajax_simple.js
Last active March 10, 2023 14:55
AJAX Simple Example
/*
**** Client Script ****
Name: CM Ajax Test
Table: Incident [incident]
UI Type: All
Type: On Load
Application: Global
Active, Inherited, Global: True (checked)
*/
//Script
@cmcdevitt
cmcdevitt / hasRoleExactely.js
Created September 1, 2022 18:42
hasRoleExactely Server Side
// https://joshneri.us/serverside-hasroleexactly-in-servicenow/
function hasRoleExactly(role) {
var au = new ArrayUtil();
var roles = gs.getSession().getRoles() + '';
var roleArray = roles.split(",");
var isAuthorized = au.contains(roleArray, role);
return isAuthorized;
}
//or maybe