Skip to content

Commit d4de02f

Browse files
authored
Auto Create Incident from Case Reply Email - Inbound Action (#2307)
* 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. * Create README.md
1 parent 69c730d commit d4de02f

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
**Auto Incident Creation from Case Email**
2+
3+
**Description**
4+
This inbound email action automatically creates an incident record when a customer replies to a case email containing keywords like outage, crash, error, or not working.
5+
The new incident links to the case as a parent and inherits caller and configuration item details.
6+
7+
**Use Case**
8+
Ideal for CSM environments integrated with ITSM, where customer issues escalate to incidents automatically.
9+
10+
**How It Works**
11+
1. The inbound email action scans the subject and body for trigger keywords.
12+
2. If a match is found:
13+
- A new incident record is created.
14+
- The incident is linked to the case as a parent.
15+
- Caller and CI are inherited if available.
16+
- Work notes of both case and incident records are updated.
17+
18+
**Inbound Action Configuration**
19+
- Table: Case[sn_customerservice_case]
20+
- Action type: Record Action
21+
- Type: Reply
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)