Skip to content

Instantly share code, notes, and snippets.

@mtcoffee
mtcoffee / GlideModalFormUIAction.js
Created August 28, 2023 15:18
GlideModalFormUIAction
//for use with ServiceNow UI Action client script to create a new Incident from a CI
function loadModal() {
var fieldquery = '';
var fields = [
'cmdb_ci=' + g_form.getUniqueValue(),
'caller_id=' + g_user.userID,
'contact_type=' + 'self-service',
'short_description=' + 'Incident for ' + g_form.getValue('name'),
];
fields.forEach(function(field) {
@mtcoffee
mtcoffee / CreateSeleniumServiceNowIncidentViaPortal.py
Created August 27, 2023 22:12
CreateSeleniumServiceNowIncidentViaPortal
import sys
if len(sys.argv) < 4:
warning = """
Please provide 3 parameters in the format "instancename username password"
e.g. dev1234 itiluser itiluserpassword
"""
print(warning)
sys.exit()
sninstance = "https://" + sys.argv[1] + ".service-now.com"
@mtcoffee
mtcoffee / CreateSeleniumServiceNowIncident.py
Last active August 27, 2023 22:10
CreateSeleniumServiceNowIncident
import sys
if len(sys.argv) < 4:
warning = """
Please provide 3 parameters in the format "instancename username password"
e.g. dev1234 itiluser itiluserpassword
"""
print(warning)
sys.exit()
sninstance = "https://" + sys.argv[1] + ".service-now.com"
@mtcoffee
mtcoffee / nesssus_servicenow.js
Created July 28, 2023 01:15
Nessus Scanner API Query ServiceNow background script
/*
MID SERVER WILL NEED TO TRUST YOUR CERTIFICATE OR YOU CAN UPDATE MID CERTIFICATE POLICY FOR Intranet
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0864769
*/
var username = 'admin';
var pwd = 'pass';
var nessusHost = 'secops.domain.home';
var scanName = 'My Scan for Lab';
var midserver = 'winmid01';
@mtcoffee
mtcoffee / pre_processor.js
Created July 26, 2023 20:49
SN Certmgmt exclude pre processor
function checkIfRecordExists(payloadItem) {
var certGr = new GlideRecord('cmdb_ci_certificate');
certGr.addQuery('fingerprint', payloadItem.values['fingerprint']);
certGr.query();
return certGr.next() ? certGr : "";
}
var rtrn = {};
//parsing the json string to a json object
var target = new GlideRecord('sys_email');
target.initialize();
target.type = 'received';
target.subject = "Test Email Subject";
target.recipients = "itdept@domain.com";
target.origemail = "bob.smith@domain.com";
target.body = "sample email body for description";
target.body_text = "sample email body for description";
target.headers = "From:Bob Smith <bob.smith@domain.com> \
To:itdept@domain.com \
<#
.DESCRIPTION
To silently install the ServiceNow MID Server on a Windows system.
Place the file on the target MID Server host machine, update the variables at the top
and run it in PowerShell.
#>
$MSI_FILE_NAME = "C:\temp\winmid.msi"
$INSTALL_LOCATION = "C:\winmid"
$INSTANCE_URL = "https://dev1234.service-now.com/"
@mtcoffee
mtcoffee / gist:e5f6b9167d308d5464e8664488fef082
Created July 4, 2021 22:11
ServiceNow conditionally customize subject of email
<mail_script>
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery("sys_id", current.request_item);
ritm.query('cat_item.name', 'Standard Laptop');
ritm.query();
if (ritm.next()) {
photoshop = ritm.variables.photoshop;
email.setSubject("New Laptop requested and photoshop is set to " + photoshop + " " + current.number);
}
</mail_script>
@mtcoffee
mtcoffee / add RITM variables to task
Created July 4, 2021 22:02
mail script to add ServiceNow RITM variables to Task
//custom function to retrieve all variables from a RITM and print in email
//https://community.servicenow.com/community?id=community_question&sys_id=c8eff1461b4b6050ed6c9979b04bcb59
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Add your code here
template.print("Summary of Related Requested item:<br />");
@mtcoffee
mtcoffee / add RITM variables to request
Created July 4, 2021 21:57
mail script to add ServiceNow RITM variables to Request
//custom function to retrieve all variables from a RITM and print in email
//https://community.servicenow.com/community?id=community_question&sys_id=c8eff1461b4b6050ed6c9979b04bcb59
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Add your code here
template.print("Summary of Requested items:<br />");