-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServiceNow Customization-Run a Response Play from a Form Button on Incident.js
77 lines (62 loc) · 2.11 KB
/
ServiceNow Customization-Run a Response Play from a Form Button on Incident.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
# Run a Response Play from a ServiceNow Incident
#
# (From SNOW Training for ES with Sean Higgins, Nov. 2018)
#
# Customizations:
# - Update to PagerDuty Script Include file
# - New UI Action
#
# Requires: Response Play ID
#
#
*/
runResponsePlay: function (incident) {
var pd = new x_pd_integration.PagerDuty();
var userEmail = pd.getValidEmail(gs.getUserID());
var rest = new x_pd_integration.PagerDuty_REST();
//feature = API endpiont to hit
var feature = 'response_plays/<RESPONSE_PLAY_ID>/run';
// helper function to get incident ID from SNOW incident
var incidentID = x_pd_integration.TaskEntityHelper.getPdId(incident);
gs.debug("The incidentID is: " + incidentID);
var postBody = {
"incident": {
"id": '"' + incidentID + '"',
"type": "incident_reference"
}
};
gs.debug("The postBody is: " + postBody);
var response = rest.postREST(feature, postBody, userEmail);
var body = this.JSON.decode(response.getBody());
var status = response.getStatusCode();
gs.debug("Successfully ran the response play!");
if (response.haveError()) {
var errCode = body.error.code;
var errors = body.error.errors.toString();
var errorMessage = 'error: ' + body.error.message;
this._setError(me, errCode + ':' + errorMessage + ':' + errors);
return;
}
if (status == 200 || status == 201) {
gs.debug('{0} body.user = {1}', me, this.JSON.encode(body.user));
var userId = body.user.id;
gs.debug('{0} userId = {1}', me, userId);
this._updateUser(user, userId);
return userId;
} else {
this._setError(me, 'unknown error, (' + status + ') body:' + response.getBody());
}
}
/*
# UI Action
#
# Action Name: (Shows up on Form Button) Run <NAME> Response Play
# Condition: !gs.nil(current.x_pd_integration_incident)
#
# Form Button
#
*/
var pdp = new x_pd_integration.PagerDuty();
pdp.runResponsePlay(current);
gs.addInfoMessage("Successfully ran Response Play");