Inbound Action on Incident Resolution

MichaelW
Tera Contributor

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();
}

 

1 ACCEPTED SOLUTION

Community Alums
Not applicable

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

View solution in original post

17 REPLIES 17

Hi,

 

Thanks for trying but still got the same issues.  It just seems to ignore the assignment group stuff.  The content goes into the comments but that's it.

Do you have any mandatory field that needs to be filled in before closing the incident?

Also is you comments updating in the ticket?


Please mark this response as correct or helpful if it assisted you with your question.

Any of them are already completed when it was set to resolved so won;t be anything new as such.

 

Yes the email reply it being placed into the comments.

Actually comments are just a copy of the email for both, so the accept one isn't displaying the message it should.

Can you check if there is any UI policy or script which is restricting the state to be changed back to new from resolved?

Also, check if you are seeing this in your log

                    gs.log("Michael : reopen INC");

if yes, kindly upload the latest script here to debug.