How to stop users from replying to Closed incidents (Which reopens the Incident)

cdavis22
Tera Contributor

Hi All,

 

I need some help with my the code below. Not sure how to check if the state is closed when an inbound email is received. My code below changes our state to follow up when an inbound email is received but here's the thing if someone replies to a closed incident it basically reopens the ticket. Was hoping someone can help me with adding in a piece of code that checked if the state is closed first & then proceed with finishing the rest of the code out??

 

Update Incident (Inbound Email Action)

 

gs.include('validators');

if (current.getTableName() == "incident") {

    var gr = current;

    if (email.subject.toLowerCase().indexOf("please reopen") >= 0)
        gr = new Incident().reopen(gr, email) || gr;

    gr.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;
    gr.u_inbound_email_received = 'true'//custom trigger for inbound replies
    gr.state = 9;
    gr.incident_state = 9;
    
    if (gs.hasRole("itil")) {
        if (email.body.assign != undefined)
            gr.assigned_to = email.body.assign;

        if (email.body.priority != undefined && isNumeric(email.body.priority))
            gr.priority = email.body.priority;
    }

    //if (gr.canWrite())
    gr.update();
}

 

Also would like to add that I tried adding in "gr.incident_state != 3;"  between gr.u_inbound & gr.state but it did not work.

Thank you!
4 REPLIES 4

jcmings
Mega Sage

What does state = 9 represent? 

cdavis22
Tera Contributor

A new choice we added into the state field.

 

9 = "Follow Up" while the value for closed is "3"

I don't have a ton of experience with Inbound Emails, but I think your issue is an OOTB flow is clashing with your BR. Check to see if you have a flow called "Update Case via Reply" (look in Flow Designer or in Process Automation > Flow Administration > Inbound Email Flows). I would try to handle your actions through there.

cdavis22
Tera Contributor

I'm not surprised my instance doesn't have the flow mentioned above but maybe I should create a flow that blocks emails for closed tickets??