Skip to content

Instantly share code, notes, and snippets.

View bajpaik's full-sized avatar
:electron:
Focusing

Kush Bajpai bajpaik

:electron:
Focusing
  • Australia
  • 07:08 (UTC -12:00)
View GitHub Profile

ServiceNow UI Developer cheat sheet


Utility URLs

URL Purpose
/stats.do Quick stats
/cache.do Clear your instance cache
@bajpaik
bajpaik / read_attachment_into_task.wf
Created September 29, 2019 13:44 — forked from asimpkin/read_attachment_into_task.wf
ServiceNow workflow script to read a TASK attachment and put the comments into a JSON format within the task.
var tableName = 'sc_req_item';
var sysIDOfRecord = current.sys_id;
//Declare a new instance of GlideSysAttachment.
var gsa = new GlideSysAttachment();
//Get the raw bytes in the file
var bytesInFile = gsa.getBytes(tableName, sysIDOfRecord);
//Convert that jive into a string using Java/Rhino.
var dataAsString = Packages.java.lang.String(bytesInFile);
//Re-convert to a string in Javascript, cause we don't trust Rhino.
csv = String(dataAsString);
@bajpaik
bajpaik / create_checklist_from_UI_action.br
Created September 29, 2019 13:42 — forked from asimpkin/create_checklist_from_UI_action.br
Business Rule to create checklist and items from a given template into a task record
/*
The following business rules have been disabled to prevent worknotes from checklist/item changes
https://central1.service-now.com/sys_script_list.do?sysparm_query=GOTOnameLIKECRUD
*/
// Get the template data with the checklist items
var gr = new GlideRecord('checklist_template');
gr.get('dcc0b5e6373fa200afb4d02783990ef5'); // TEST TEMPLATE
var json = JSON.parse(gr.template);
@bajpaik
bajpaik / getXMP.php
Created September 29, 2019 13:40 — forked from asimpkin/getXMP.php
PHP function to query ServiceNow REST API to GET a list of records from a table.
<?php
date_default_timezone_set('America/Los_Angeles');
DEFINE("INSTANCE","central1");
DEFINE("SITE", "http://".$_SERVER['SERVER_NAME']); // ENABLE THIS LINE WHEN PUSHED TO PROD
DEFINE("USER","username");
DEFINE("PASS","password");
function getXML($table,$query) {
@bajpaik
bajpaik / sn_audit_restore.ps
Created September 29, 2019 13:39
Revert ServiceNow CI data from the audit log within a date range.
$sncusername = "MisterMistersBusiness"
$sncpassword = ConvertTo-SecureString "BLAHBLAHBLAH" -AsPlainText -Force
$snccredentials = New-Object System.Management.Automation.PSCredential ($sncusername, $sncpassword)
$StartDate = ((Get-Date).Year).ToString() + "-" + ((Get-Date).Month).ToString() + "-" + ((Get-Date).AddDays(-01).Day).ToString()
$EndDate = ((Get-Date).Year).ToString() + "-" + ((Get-Date).Month).ToString() + "-" + ((Get-Date).Day).ToString()
$Results = (Invoke-RestMethod -Method Get -Uri "https://central1.service-now.com/api/now/table/sys_audit?sysparm_query=user=snc_discovery_user^fieldname!=DELETED^sys_created_on>javascript:gs.dateGenerate('$StartDate','23:00:00')^sys_created_on<javascript:gs.dateGenerate('$EndDate','01:00:00')" -Credential $snccredentials).Result
$ComputerIDs = $Results | Select documentkey -Unique
Foreach ($Record in $Results) {
// Callback functions
//built-in callback functions
//setTimeout, Arr.forEach, geolocation.getCurrentPosition
//make your own callback functions
//setTimeout( hello, 2000, 'Bob')
let names = ['Inga','Tom','Mattias','Carlos'];
names.forEach(hello);
@bajpaik
bajpaik / servicenow_rest_attachment_api_python_mulitpart_example.py
Created December 14, 2018 10:06 — forked from bryanbarnard/servicenow_rest_attachment_api_python_mulitpart_example.py
ServiceNow REST Attachment API Example Python Example using /now/attachment/upload endpoint to post (upload) a file as an attachment to an incident as multipart form data.
# This example uses the Python Requests Library and you will need to install requests package for python
# Documentation can be found at http://docs.python-requests.org/en/master/user/quickstart/
import requests
import pprint
import json
# Specify the Endpoint URL replacing {servicenow_instance_name} with your ServiceNow Instance Name
url = 'https://{servicenow_instance_name}.service-now.com/api/now/attachment/upload'