- 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-21-2019 02:59 PM
I will do some more testing shortly. Our Dev area has just been wiped to match Prod area and then later today will update to London in preparation for moving Prod to London. I will start doing some testing again shortly though. I will test and get some email logs and see what other inbound actions are running. There should be 4 all up for Incident from memory.
As for below that and the original inbound action was done by the partner the business employed to setup Service Now for us. We are only about 3 months in using it as the live environment. I've however found that the rule they made doesn't work at all and have been trying to improve it and get it going.
Thanks
- 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-21-2019 03:49 PM
Hi Raf,
Ok I disabled a second inbound action that might have been affecting them and wasn't needed.
Disabled the inbound action and created a new one for testing, modified script to yours above (removed the 3rd comments option as I don't want that knocking back to open) and reject and accept are now working fine, adding notes and changing state.
So i think it was a combination of the second rule causing issues and your adjustments being nice.
Thanks for your help.