Skip to content

Instantly share code, notes, and snippets.

@asimpkin
asimpkin / curl_connect.sh
Last active November 8, 2024 19:06
Shell Script Curl Connect to ServiceNow
#!/bin/bash
curl -u USERNAME:PASSWORD -k 'https://[instance].service-now.com/change_request.do?JSONv2&sysparm_query=YOUR_QUERY'
# -u will perform basic auth anformat your USERNAME:PASSWORD to bas64.
# -k will not check SSL certificate if you don't have certficate setup
@asimpkin
asimpkin / coffee_event.io
Last active March 17, 2016 22:19
Particle code for button push of coffee event
int button = D0; // the button to press to order the coffee..
int led = D7; // The built in LED..
int counter = 0;
void setup() {
// Setup the inputs and outputs
pinMode(button, INPUT_PULLDOWN);
pinMode(led, OUTPUT);
@asimpkin
asimpkin / create_CHG.ps1
Last active August 29, 2015 14:20
Use PowerShell to create CHG using ServiceNow Web Services
$COURI = 'https://central1dev.service-now.com/change_request.do?WSDL'
$ApprovalURI = 'https://central1dev.service-now.com/sysapproval_approver.do?WSDL'
$ECCURI = 'https://central1dev.service-now.com/ecc_queue.do?WSDL'
$username = "SERVCIEACCOUNTUSER"
$password = ConvertTo-SecureString "PASSWORD" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ($username, $password)
# Prep the mac file
$MacContent = Get-Content H:\Mac.csv -Raw
$MacBase64Content = [System.Text.Encoding]::UTF8.GetBytes($MacContent)
@asimpkin
asimpkin / GetCiForCMDB_CI.js
Created February 19, 2015 19:49
ServiceNow Business Rule - Advanced Reference Qualifier for TASK.cmdb_ci
function GetCiForCMDB_CI() {
var a = '';
if(current.u_root_cause=='3rd Party') { // restrict to 3rd party business services when root cuase is C1 Supplier
var gr = new GlideRecord('cmdb_ci');
gr.addQuery('sys_class_name', 'u_cmdb_ci_service_3rdparty');
gr.query();
while (gr.next()) {
if (a !='') {
a = a + '^ORsys_id='+ gr.sys_id ;
} else {
@asimpkin
asimpkin / gen_kpis
Last active August 29, 2015 14:15
ServiceNow Business Rule - Generate KPIs
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Generate_Row_Count( TASK_TYPE, KPIPERIOD, QUERY, PORTFOLIO, SYS_ID ) { // GET CURRENT MONTH KPI VALUE
var QSTR = QUERY ;
if(PORTFOLIO) {
if(TASK_TYPE=='change_request') { var PP = 'cmdb_ci.u_ci_portfolio' } else { var PP = 'u_portfolio'; }
QSTR += '^'+ PP + '=' + PORTFOLIO ;
}
// gs.addInfoMessage( QSTR );
var gr = new GlideRecord( TASK_TYPE );
@asimpkin
asimpkin / Big_Board_Display_Example.php
Created October 27, 2014 19:00
A code example for display boards using PHP and CURL to query the ServiceNow instance.
<?php
include("../common.inc.php"); // Contains definitions for INSTANCE, USER, PASS
$query=urlencode('active=true^stateNOT IN6,^priorityIN1,2'); // Active, NOT Resolved, Hi Priority INC
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://'.INSTANCE.'.service-now.com/incident_list.do?XML&useUnloadFormat=true&sysparm_query='.$query);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
@asimpkin
asimpkin / data_diff.js
Created October 21, 2014 16:11
ServiceNow UI Action to calculate and display date diffs
action.setRedirectURL(current);
var DIFF = gs.dateDiff(current.u_bcp_last_test.getDisplayValue(), gs.now(), true)
gs.addInfoMessage(DIFF);
gs.addInfoMessage(gs.yearsAgo(2));
gs.addInfoMessage(gs.dateDiff(current.u_bcp_last_test.getDisplayValue(), gs.now(), true));
gs.addInfoMessage(gs.dateDiff('2014-10-01 00:00:00', gs.now(), true));
gs.addInfoMessage(gs.dateDiff('2013-10-07 22:50:17', gs.now(), true));
gs.addInfoMessage(gs.dateDiff('2012-10-07 22:50:17', gs.now(), true));
@asimpkin
asimpkin / linux_servers_wo_applications.php
Last active August 29, 2015 14:07
A script to query the ServiceNow CMDB locating Linux production servers wo. an application relationship.
<?php
include("../common.inc.php");
start_page("Linux Servers without Provides Production For :: Applications");
// get stuff
$arr = getXML('cmdb_ci_linux_server','operational_status=1');
// query for a production relationship where the parent is the application
foreach($arr as $k => $v) {
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate>
var R = new GlideRecord('grc_risk');
R.orderBy('likelihood.weighting');
R.query();
</g:evaluate>
<h1>Inherent Risk Summary</h1>
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<script language="javascript" src="/scripts/prototype-adapter.jsx" />
<script language="javascript" src="/scripts/GlideV2ChartingIncludes.jsx" />
<script>
document.observe("dom:loaded", function() {
var chart1 = new Highcharts.Chart({
chart: {
renderTo: 'newchart',
type: 'bubble',