- 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-17-2019 09:53 PM
They can be changed by staff nor problem and if I setup business rules etc they can change the state.
Nothing showing in the log so not getting that far.
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();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2019 09:57 PM
Could you add another log at the top like this and see to know exacty where it is failing
gs.log("entered here 1");
if (current.getTableName() == "incident") {
gs.log("entered here 2");
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){
gs.log("entered else 1");
current.comments = "Resolution accepted. Incident closed";
current.state =7; // Set state to Closed
current.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2019 04:31 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2019 06:58 AM
Hello MichaelW,
It looks like your inbound action is not being fired. Can you go to inbound actions and check what all inbound actions running on incident and disable them and keep only this active and check once.
And then see if your code is executing or not.
I suspect some other inbound action is running and it sopping further processing of other actions.
Mark it as helpful if this helps you to debug the problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2019 07:33 AM
MichaelW, can you send us the received email log? I would like to check if your inbound action was triggered. The notification only is triggered after by passing inbound action.