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

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


               }


}

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


               }


}

 

 

Added more logs but nothing showing in log for any of the 3 steps.  Only log is it fires Incident commented Notification.  So doesn't appear to be firing rule at all.

 

find_real_file.png

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.

Community Alums
Not applicable

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.