- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2019 04:50 PM
Hi,
We have a rule in place that when an Incident is resolved it fires off an email to the caller asking them to accept or reject the resolution. This side of things works fine and when that hit the links that creates an email response the systems updates the incident with the response. I can't however get it to alter the state. Any suggestions on what i'm doing wrong? Here is my current code.
gs.include('validators');
if (current.getTableName() == "incident") {
var gr = current;
if (email.subject.toLowerCase().indexOf("reject") >= 0 && gr.state==6) {
gs.log("Michael : reopen INC");
gr = new Incident().reopen(gr, email) || gr;
gr.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;
gr.state = 1; // Set state to new
} else if (email.subject.toLowerCase().indexOf("accept") >= 0 && gr.state==6){
gr.comments = "Resolution accepted. Incident closed";
gr.state =7; // Set state to Closed
}
gr.update();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2019 06:05 AM
May I ask why or where did you got "gr = new Incident().reopen(gr, email) || gr;"?
That is the OOTB inbound action for the incidents:
gs.include('validators');
if (current.getTableName() == "incident") {
current.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;
if (gs.hasRole("itil")) {
if (email.body.assign != undefined)
current.assigned_to = email.body.assign;
if (email.body.priority != undefined && isNumeric(email.body.priority))
current.priority = email.body.priority;
}
current.update();
}
To accept/reject a resolution you have 3 options: read subject, read body or read both. The best option is the 3rd. The following example is available in the CSM module as "Update Case via AcceptReject". You can use add validators check if you want, it allows you to validate the data coming in when you script is looking for input. Things like isNumeric, or isInteger or containsOnlyChars.
if (current.state == 6) {
var subject = email.subject.trim().toLowerCase();
if(subject.indexOf("reject") === 0){
current.state = 10;
}else if(subject.indexOf("accept") === 0){
current.state = 3;
}
current.update();
}
Going a little bit further..
if (current.state == 6) {
var lines = email.body_text.split('\n');
var firstword = "";
if (lines.length > 0)
firstword = lines[0].replace(/^\s+|\s+$/g, '');
firstline = firstword.toLowerCase();
if (firstline) {
// Accept solution
if (firstline.indexOf("accept") == 0) {
current.state = 7;
current.comments = 'Solution acccepted by: ' + email.from + '\n\n' + 'Close notes: ' + current.close_notes;
}
// Reject solution
else if (firstline.indexOf("reject") == 0) {
current.comments = 'Solution rejected by: ' + email.from + '\n\n' + 'Close notes: ' + current.close_notes;
current.state = 1; // Updated case to "New"
current.close_notes = '';
}
// Receive comment
else {
current.comments = 'Comment received by: ' + email.from + '\n\n' + 'Close notes: ' + current.close_notes;
current.state = 1; // Updated case to "New"
current.close_notes = '';
}
}
current.update();
}
Thank you,
Raf

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2019 05:08 PM
Try this
gs.include('validators');
if (current.getTableName() == "incident") {
if (email.subject.toLowerCase().indexOf("reject") >= 0 &¤t.state==6) {
gs.log("Michael : reopen INC");
current = new Incident().reopen(current, email) ||current;
current.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;
current.state = 1; // Set state to new
} else if (email.subject.toLowerCase().indexOf("accept") >= 0 &¤t.state==6){
current.comments = "Resolution accepted. Incident closed";
current.state =7; // Set state to Closed
}
current.update();
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2019 05:30 PM
I've tried that combo already and didn't work either.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2019 05:43 PM
Had tried similar with no luck but tried above and still the same.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2019 10:22 PM
Hello Michael
Try this code. Current already points to the current record, so you don't need to set it again.
gs.include('validators');
if (current.getTableName() == "incident") {
if (email.subject.toLowerCase().indexOf("reject") >= 0 && gr.state==6) {
gs.log("Michael : reopen INC");
//gr = new Incident().reopen(gr, email) || gr;
current.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;
current.state = 1; // Set state to new\
current.update();
} else if (email.subject.toLowerCase().indexOf("accept") >= 0 && gr.state==6){
current.comments = "Resolution accepted. Incident closed";
current.state =7; // Set state to Closed
current.update();
}
}
Kindly mark my answer as correct if this works.