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 / business_unit_analysts.js
Last active September 1, 2022 18:14
Filter Records for a 'Business Unit' Analysts. Typically an Analysts can see everything, but you may need them just to see only their BUs stuff
/*
1. Grant the user the Analysts role, for example: sn_vul.vulnerability_analyst
2. Grant the user the NEW BU Analysts role (that you created for this), for example: sn_vul.vulnerability_bu_analyst
Note: the new role does not need to have any ACLs or anything else
3. Create an On Before, Query Business Rule (Order 10,000)
*/
gs.getUser().hasRole('sn_vul.vulnerability_bu_analyst');// <== BR Condition, only run this for BU Analysts
//In canned BR function
if(!gs.hasRole('admin')){//Don't run it for Admins
@cmcdevitt
cmcdevitt / script_action_handler.js
Last active September 1, 2022 15:03
Script Action :: Script Action Handler via Script Include
/*
==> (1) Script Action <==
Script Actions seem slow and difficult to troubleshoot
So.... Lets move the logic to a Script Include where we can simulate and troubleshoot a lot easer...
*//
//In Script Action example....
var util = new global.ChangeRequestUtil(current,event);// <== Pass in current and event as args when instantiating the SI
util.utilKnows(); //Then call methods without arguments becouse the SI already know about current and event
util.fooBar();
//...
@cmcdevitt
cmcdevitt / di_os_cleanup.js
Created August 18, 2022 20:04
Discovered Item OS org.mozilla clean up
var gr = new GlideRecord("sn_sec_cmn_src_ci");
gr.addEncodedQuery("osSTARTSWITHorg.mozilla.javascript.NativeArray");
//gr.setLimit(100);
gr.query();
while (gr.next()) {
var sourceData = JSON.parse(gr.getValue("source_data"));
var os = sourceData["operating_system"];
if (os) {
//"operating_system" object found in Source Data
@cmcdevitt
cmcdevitt / gen_tanium_api_key.js
Created August 8, 2022 20:41
Generate Tanium API Key via ServiceNow
/*
How to call the Script Include
var util = new sn_vul.TaniumUtilities();
var out = util.login();
This requires a REST Message called "Tanium"
HTTP Method: (POST) Login, Endpoint: ${baseURL}/api/v2/session/login, Authentication type: No authentication
Note: You may need use select a MID server if this is on Prem (HTTP Method -> HTTP Request: Use MID Server
*/
var TaniumUtilities = Class.create();
@cmcdevitt
cmcdevitt / javascript_chaining.js
Last active August 7, 2022 18:37
JavaScript Chaining How To
var ChainIt = Class.create();
ChainIt.prototype = {
initialize: function() {
//Persistence varables go here.... maybe an object
this.answer = '';
},
addAnswer: function(add_it){
//add_it = string
this.answer = add_it;
@cmcdevitt
cmcdevitt / db_view_2_update_set.js
Created August 5, 2022 16:48
Save a Database View to an Update Set
/*
Database View[sys_db_view]
Field Name[name]
View Tables [sys_db_view_table]
View [view] -> Database View
View Fields [sys_db_view_table_field]
View Table [view_table] -> View Table
*/
@cmcdevitt
cmcdevitt / assign_via_teams.js
Created August 4, 2022 19:45
VR Assignment Rules using a Script for the Teams [cmdb_rel_team] table
/*
On a Configuration Item Table (i.e. CMDB) you can add a Teams[cmdb_rel_team] you can add a "Teams" Related List that can hold
multiple Assignment Groups.
This is how you access it in an assignment Rule
*/
function getAssignment(ci,group_type){
var default_assignment_group = '679434f053231300e321ddeeff7b12d8';//Set with gs.getProperty()
var teams = new GlideRecord('cmdb_rel_team');//Teams Table
teams.addEncodedQuery('group_type=' + group_type + '^ci=' + ci);
teams.setLimit(1);
@cmcdevitt
cmcdevitt / emptySubCategoryCheck.js
Last active August 3, 2022 17:55
Check a Subcategory / Options to see if it is empty
//Get the DOM Element and it's undocumented
var subcat = g_form.getElement('subcategory');//Any "Choice" List
if(subcat.length > 1){ // i.e. it's not Empty
//Do something cool!
}else{
//Do something cool!
}
/*
Choice List are HTML Options
@cmcdevitt
cmcdevitt / check_set_date.js
Created July 13, 2022 17:46
Check and Set Date
checkDateFormat: function(date) {
//A very simple regex to see if the incoming data is compatable with the SN Date field
var answer = false;
var regexps = /[0-9]{4}-[0-9]{2}-[0-9]{2}/; // example 2022-02-28
if (regexps.test(date)) {
answer = true;
}
return answer;
@cmcdevitt
cmcdevitt / assign_rules_teams.js
Last active June 27, 2022 21:53
Uses Teams [cmdb_rel_team] - Related List on Configuration Item for VR Assignment Rules
/*
https://docs.servicenow.com/bundle/tokyo-servicenow-platform/page/product/configuration-management/reference/r_RelatedListsOfCIComponents.html
Docs: Related Lists of CI components
Use Case
You can not add an Assignment Group to the CMDB, and you want to use the 'Teams' CI Related List instead
*/
//Assignment Rule :: Assign Using :: Script