Skip to content

Instantly share code, notes, and snippets.

@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>
<#
.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/"
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 \
@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
@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 / 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 / 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 / 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 / ServiceNowMIDServerTest.js
Created August 28, 2023 17:16
ServiceNow MID Server Test
/*
A background script to run a command and test MID Server connectivity to an endpoint.
Just set the value to your midserver name.
*/
//capture start time
var now = (new GlideDateTime());
var probe = SncProbe.get("Windows - Powershell");
var midServer = 'winmid06';
var psCommand = 'test-netconnection -port 443 192.168.1.1';
@mtcoffee
mtcoffee / updateDescription.js
Created September 21, 2023 18:28
Script to Build a Modal from a ServiceNow UI Action
function showModal() {
// get current values from description
var currentOutageDetails = g_form.getValue('description');
var securityStatus = getCurrentValueSingle(currentOutageDetails, 'Potential Security Issue:');
var businessStatus = getCurrentValueSingle(currentOutageDetails, 'Business Operation Affected:');
var symptomStatus = getCurrentValueSingle(currentOutageDetails, 'Reported Symptoms:');
var descStatus = getCurrentValueMulti(currentOutageDetails, 'General Description:');
var gm = new GlideModal('Set Description');
gm.setTitle('Set Description');