Skip to content

Instantly share code, notes, and snippets.

View acary's full-sized avatar

Andy Cary acary

View GitHub Profile
Your BetaQ embed code
@acary
acary / create-incident
Created November 21, 2016 21:22
Saving state for working Create Incident inbound email action 11/21
// Saving state for working Create Incident inbound email action 11/21
// Note: current.opened_by is already set to the first UserID that matches the From: email address
current.caller_id = gs.getUserID();
current.short_description = email.subject;
current.work_notes = "received from: " + email.origemail + "\n\n" + email.body_text;
current.category = "inquiry";
current.incident_state = IncidentState.NEW;
@acary
acary / gist:8841b6ccb2da009cfa6b913b23df429b
Last active November 21, 2016 22:59
Create Request (Subject)
// This creates a request if email subject includes "request"
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
// Implement email action here
if (email.subject.toLowerCase().indexOf('request') >= 0) {
createRequest();
}
function createRequest() {
@acary
acary / gist:5f8adc66e53e70bdaca71fbb0a777df4
Created November 22, 2016 17:56
Update Incident (Close added)
gs.include('validators');
if (current.getTableName() == "incident") {
var gr = current;
if (email.subject.toLowerCase().indexOf("please reopen") >= 0)
gr = new Incident().reopen(gr, email) || gr;
gr.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;
@acary
acary / gist:91a827e547bfb0064c8cf7cddf80c06f
Created November 22, 2016 20:14
Close Incident (Email)
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
gs.include('validators');
// Close if subject matches close template
if (email.subject.toLowerCase().indexOf("close") >= 0) {
if (String(email.subject).indexOf("INC")!=-1){
var index = String(email.subject).indexOf("INC");
var incident = String(email.subject).substring(index,index+10);
@acary
acary / gist:98427b9473e5c946b6c18a65f50a1a62
Last active November 24, 2016 00:03
Getting parent department name for a given user
// Call user
var ourUser = gs.getUser();
var ourUser = ourUser.getUserByID('dfda7e034f86020058c6f0318110c7a6'); //fetched a different user, using the user_name field or sys_id on the target user record.
// Show user's full name
gs.print('Full Name: ' + ourUser.getFullName());
// Get user department
var userDepartment = ourUser.getDepartmentID();
gs.print('DepartmentID: ' + userDepartment); // Prints Department sys_id
@acary
acary / script-user-dept.txt
Created November 28, 2016 21:31
Get user's department and budget unit
/*
Below gets user, department, and budget unit,
Including up one parent level.
Working to get parent information automatically,
Versus hard-coding the dot-walk to immediate parent
*/
getUser('dfda7e034f86020058c6f0318110c7a6');
function getUser(userId) {
@acary
acary / DisplayParents
Last active December 1, 2016 21:46
DisplayParents (Script Include)
var DisplayParents = Class.create();
DisplayParents.prototype = Object.extendsObject(AbstractAjaxProcessor, {
initialize: function() {
},
// Get user
getUser: function(sys_id) {
// Call user
@acary
acary / 1 Get Country
Created December 6, 2016 17:37
ServiceNow REST API Get Country
// Updates Incident record with alpha3_code returned from JSON Object
function updateCountry() {
current.u_alpha3_code = mycountry;
current.update();
}
try {
var r = new sn_ws.RESTMessageV2('Country Codes Global', 'get');
r.setStringParameter("text", incident.u_country); // uses country value in request
@acary
acary / gist:43f6462114e46dcca73c01093a37c675
Last active November 1, 2019 15:39
Code review example
# File: feed.py
from app.home.trending import report_trending
from app.home.recent import report_recent
def get_feed(current_topic):
'''Build unique feed from trending and recent feed sources.'''
# Get posts
trending_posts = report_trending(current_topic)
recent_posts = report_recent(current_topic)