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 / getincident.js
Created February 15, 2018 22:15
ServiceNow Test Scripted RESTAPI GET
///api/auclg/chris_test/get_incident/{id}
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
2
3
//INC0010808
4
var uri = request.uri;
5
var url = request.url;
@cmcdevitt
cmcdevitt / createnewincident.js
Created February 15, 2018 22:19
ServiceNow RESTAPI Create Incident
// /api/auclg/v1/chris_test/incident
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
//Creat Incident
//Manadatory: Caller, Configuration Item, Assignment Group, Short Description
//"Chris McDevitt,
//ServiceNow How To, 006689dc6ff70900f71de82fae3ee4f5
//Service Desk, d625dccec0a8016700a222a0f7900d06
//What ever
//caller_id, cmdb_ci, assignment_group, short_description
@cmcdevitt
cmcdevitt / updateIncident.js
Created February 15, 2018 22:21
ServiceNow RESTAPI update incident
// api/auclg/v1/chris_test/incident/{number}
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// implement resource here
var caller;
var configurationItem;
var assignmentGroup;
var shortDescription;
var work_notes;
@cmcdevitt
cmcdevitt / exploreobject.js
Last active February 26, 2018 01:47
Explore Global Object or Explore Object to see its methods and properties
// "this" is bound to the global object in the browser
// If strict is used then "this" is undefined
//let myObject = this; //Of course you can look at any object
//var myObject = this;
var myObject = { one: "One",
two: function(){return "Hello";}};
for(objExplore in myObject){
if(!objExplore.hasOwnProperty(objExplore)){ //note: "Don't searching Prototype Chain"
console.log(objExplore + " " + typeof(myObject[objExplore]) );
@cmcdevitt
cmcdevitt / catalog_client_script.js
Created May 4, 2018 19:07
Service Portal / Service Catalog GlideAjax lookup errors catalog client scripts
ga.getXML(parseResponse);
// old (DOM Method)
var result = response.responseXML.getElementsByTagName("result");
//New (JSON Parse Technique)
//Use with Asynchronous GlideAjax calls with "getXMLAnswer" (not "getXML")
var result = JSON.parse(answer);
___________________________
Code snippett for part 1
___________________________
task.cmdb_ci = current.cmdb_ci;
task.short_description = 'Emergency change request for high security vulnerability : ' + current.vulnerability.id;
task.work_notes = 'This Change record was created by the system for audit purposes. The Vulnerability Patch for ' + current.vulnerability.id + ' was installed automatically.';
___________________________
Code snippet for part 2
@cmcdevitt
cmcdevitt / hide_tab.js
Created May 18, 2018 19:29
ServiceNow Hide a Section Tab Client Script
function onLoad() {
var userID = g_form.getReference('caller',rb);
}
//if request is submitted by user X
function rb(userID){
if (userID.user_name == "X" ){
g_form.setSectionDisplay("sometabname", true);
}
@cmcdevitt
cmcdevitt / record_producer.js
Created June 5, 2018 14:22
Record Producer that call's itself and returns its number
current.u_ridac_type = "Issue";
current.u_product = "f46762b60fd61780b6422ca8b1050e79";
current.description = current.description + "\nLocation: " + producer.office_location;
current.description = current.description + "\n\n************************************";
current.description = current.description + "\nPhone: " + producer.phone_issues_;
current.description = current.description + "\nDesktop: " + producer.desktop_issues_;
current.description = current.description + "\nPrinting : " + producer.printing_issues_;
current.description = current.description + "\nInternet : " + producer.internet_issues_;
current.description = current.description + "\nOne : " + producer.place_holder_one_;
@cmcdevitt
cmcdevitt / scripted_rest.js
Last active January 21, 2021 19:58
Scripted REST Web Service
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var caller; //Manadatory ServiceNow User
var cmdb_ci; //Manadatory Varies need to provide list
var shor_description; //Manadatory text 40 charters
var company; //Manadatory "xxx | xxxx | xxx | xxxx"
var requestBody = request.body;
var requestData = requestBody.data;
@cmcdevitt
cmcdevitt / reassign_vulgrp_ui_page.xml
Created August 24, 2018 15:26
Update Vulnerability Group(s)'s Assignment Group and Work Notes (London)
<?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 testIds = RP.getWindowProperties().get('test_ids');
var testQuery = RP.getWindowProperties().get('test_query');
</g:evaluate>
<div id="reassign_vulgroup_picker_container" >
<div class="form-group">