Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
ServiceNow Assigned Incident Slack Notification #servicenow #slack #businessrule
// ServiceNow Assigned Incident Slack Notification
// Business Rule
// SlackIncidentAssignNotify.js
// Rich Bocchinfuso - 2017/05/10
// debug only
//var inc ='####'; // add incident sys_id you wnat to use for debugging
//var current = new GlideRecord('incident');
//if (current.get(inc)) {
// Initialize a new SlackMessage
var slack = new SlackMessage();
var incident_url = 'https://' + gs.getProperty('instance_name') + '.service-now.com/nav_to.do?uri=incident.do?sys_id=' + current.sys_id;
var assigned_previous = '\n Assigned from: ' + (previous.assigned_to != null ? + previous.assigned_to.u_slack_username.getDisplayValue() : "nobody");
// create payload
gs.info('create payload');
slack.payload.text = 'Incident ' + current.number.toString() + ' (' + current.short_description + ') ' + 'reassigned to ' + '<' + current.assigned_to.u_slack_username.getDisplayValue() + '>' + ':';
slack.payload.icon_url = 'https://www.idmworks.com/wp-content/uploads/2015/04/servicenow-icon.png';
slack.payload.attachments.push({
'title': current.number.toString() + ' (' + current.short_description + ')',
'title_link': incident_url,
'text': '\n Customer: ' + current.company.getDisplayValue() + '\n Location: ' + current.location.getDisplayValue() + '\n Opened by: ' + current.opened_by.getDisplayValue() + '\n Caller: ' + current.caller_id.getDisplayValue() + '\n Assigned from: ' + previous.assigned_to.getDisplayValue() + '\n Assigned to: ' + current.assigned_to.getDisplayValue() + '\n Category: ' + current.category.getDisplayValue() + '\n CMDB Item: ' + current.cmdb_ci.getDisplayValue() + '\n Priority: ' + current.priority.getDisplayValue() + '\n Description: ' + current.description
});
// fire message
gs.info('fire message');
slack.send();
gs.info('boom!');
//} // uncomment for debug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment