Skip to content

Commit 013baff

Browse files
authored
Create create_incident_from_case_email.js
Inbound action to create incident from case reply email and link it as a parent with inherited caller & CI.
1 parent 69c730d commit 013baff

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
2+
3+
//Extract email subject and body
4+
var subject = email.subject.toLowerCase();
5+
var body = email.body_text.toLowerCase();
6+
7+
//Define trigger keywords for creating the incident
8+
var keywords = ['outage', 'crash', 'down', 'error', 'issue', 'not working', 'failure', 'slow'];
9+
var trigger = false;
10+
11+
for(var i = 0; i < keywords.length; i++){
12+
if(subject.includes(keywords[i]) || body.includes(keywords[i])){
13+
trigger = true;
14+
break;
15+
}
16+
}
17+
18+
//Execute only if trigger word found
19+
if(trigger){
20+
//Create a new incident record
21+
var inc = new GlideRecord('incident');
22+
inc.initialize();
23+
inc.short_description = 'Auto-created from Case ' + current.number + ': ' + email.subject;
24+
inc.description = 'Customer reported via Case ' + current.number + ':\n' + email.body_text;
25+
inc.parent = current.sys_id;
26+
27+
//Link caller and CI from case to incident if available
28+
if(current.contact)
29+
inc.caller_id = current.contact;
30+
if(current.cmdb_ci)
31+
inc.cmdb_ci = current.cmdb_ci;
32+
33+
var incSysId = inc.insert();
34+
35+
//Update case work notes
36+
current.work_notes = 'Incident ' + inc.number + ' created automatically from customer email.';
37+
current.update();
38+
39+
//Add incident work notes
40+
var newInc = new GlideRecord('incident');
41+
if(newInc.get(incSysId)){
42+
newInc.work_notes = 'Auto-created from Case ' + current.number + '.\n\nEmail Content:\n' + email.body_text;
43+
newInc.update();
44+
}
45+
}
46+
})(current, event, email, logger, classifier);

0 commit comments

Comments
 (0)