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 / GrpMem
Last active August 29, 2021 07:31
ServiceNow Script Include used to return an array of user id from a group. Using this for a Scripted Filter
function GrpMem(group_name){
//This arrary will hold the user id of the group members
var arrUsers = [];
//Need to lookup user id later
var usr = new GlideRecord('sys_user');
//Need to get sys_id of the group
var grpSysId = cmGetSysID(group_name,'sys_user_group');
@cmcdevitt
cmcdevitt / gist:ff40633e3f0514c294d3
Created December 3, 2014 17:56
Add Angularjs to a ServiceNow Jelly Page
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g2:evaluate var="jvar_stamp">
var gr = new GlideRecord('sys_ui_script');
gr.orderByDesc('sys_updated_on');
gr.query();
gr.next();
gr.getValue('sys_updated_on');
</g2:evaluate>
<g:requires name="angularjs.min.1.3.2.jsdbx" params="cache=$[jvar_stamp]" />
</j:jelly>
@cmcdevitt
cmcdevitt / gist:4ccba6c3a26dbcd9d90c
Created December 16, 2014 20:22
ServiceNow Angular Demo Page
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g2:evaluate var="jvar_stamp">
var gr = new GlideRecord('sys_ui_script');
gr.orderByDesc('sys_updated_on');
gr.query();
gr.next();
gr.getValue('sys_updated_on');
</g2:evaluate>
@cmcdevitt
cmcdevitt / gist:7704051485b08a67be70
Created January 16, 2015 19:14
ServiceNow Orchestration Invoke-Command Add User to Local Group
#Note: Rember the commands are executed LOCALY on the MID server
#Note: The MID server has the same rights as the Service Account Running it.
#Note: The Service Accounts rights can be used to execute commands on remote hosts, if configured to do so
#Note: You may need to use different accounts to do what you need:
#Note: To execute on a remote windows host with a different account:
#Note: You need to rely on a PowerShell Commands which support -ComputerName & -Credential
#Note: Or you need to rap you script in the PowerShell Invoke-Command
#Test-WSMan -ComputerName $computer; #This works used to test remote connection
#Invoke-Command -ComputerName $computer -credential $cred -ScriptBlock {net localgroup administrators}; #This works
#Invoke-Command -ComputerName $computer -credential $cred -ScriptBlock {[Environment]::UserName;}; #This works
@cmcdevitt
cmcdevitt / gist:fd379664422ec5bef6b6
Created March 5, 2015 23:08
Record Producer Survey Data Test
//pick_asmt, new_exp_date, new_due_date, new_sys_crt_date, new_state -- Variable Set
//asmt_assessment_instance --> expiration_date
//asmt_assessment_instance --> due_date
//asmt_assessment_instance --> number
//asmt_assessment_instance --> sys_created_on
//asmt_assessment_instance --> state
//gs.log("CM***: " + producer.pick_asmt + " " + producer.new_exp_date);
gr = new GlideRecord("asmt_assessment_instance");
gr.get(producer.pick_asmt);
@cmcdevitt
cmcdevitt / gist:eacd303367372dd4af5e
Created March 5, 2015 23:09
Record Producer Survey Data Test
//pick_asmt, new_exp_date, new_due_date, new_sys_crt_date, new_state -- Variable Set
//asmt_assessment_instance --> expiration_date
//asmt_assessment_instance --> due_date
//asmt_assessment_instance --> number
//asmt_assessment_instance --> sys_created_on
//asmt_assessment_instance --> state
//gs.log("CM***: " + producer.pick_asmt + " " + producer.new_exp_date);
gr = new GlideRecord("asmt_assessment_instance");
gr.get(producer.pick_asmt);
@cmcdevitt
cmcdevitt / routeRP
Created May 27, 2015 18:06
Route Incident Record Producer based on a Schedule
//redirect to thank you page after submit
producer.redirect = "/ess/help_thank_you.do";
current.contact_type = 'Self-service';
var user = new GlideRecord('sys_user');
user.addQuery('sys_id','=', current.caller_id);
user.query();
if(user.next())
{ //seting Incident location and phone number from the user record
@cmcdevitt
cmcdevitt / Remove Demo CI Data
Created July 9, 2015 12:22
Remove Demo CI Data. The following script identifies the impacted CIs, checking to ensure they are not relied on by any tasks.
// remove demo data CIs
var recCI = new GlideRecord('cmdb_ci')
recCI.addEncodedQuery("sys_created_on<javascript:gs.dateGenerate('2013-09-01','00:00:00')^sys_class_name!=cmdb_ci_snc_component^ORsys_class_name=NULL")
recCI.orderByDesc('sys_created_on')
recCI.query()
var logmsg = "Log Output\nRecords Found: " + recCI.getRowCount() + "\n";
while(recCI.next()){
var taskCI = new GlideRecord('task_ci');
@cmcdevitt
cmcdevitt / addUsersToGroup.js
Created January 31, 2018 22:13
Uses this as a post clone clean up script to add users to a group
//To-Do:
//Check for instance to make this varable (i.e. test, dev,etc) gs.getProperty('instance_name');
//Should groups be an array?
//Should the user be an object? username,[alloud instance], [groups]
var groupName = "ServiceNow Impersonation";
var users = [];
var gl = new GSLog("com.glide.schedules.log.level", "cm_test");
gl.logDebug("cm_test : This is a debug message");
@cmcdevitt
cmcdevitt / open_sec_incident.js
Created February 15, 2018 12:07
ServiceNow Scripted RESTAPI
// POST /api/auclg/v1/si/security_incidents
// Content-Type application/json Accept application/json
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
//Creat Security Incident
var caller;