how to add a button in email notification to close or reopen a case

AndresGc
Tera Contributor

Hello team, I am with a case that I had not dealt with before, it is requested to add the options to accept or reject the case once it enters the "resolved" state, that in the case states would be "closed" or "open", previously I had created an email script that does it from url, I don't know if I used it to change the status of the record, I also relied on the email script for incidents but I couldn't get it to work

 

 

(function runMailScript(current, template, email, email_action, event) {
    
    var gr = new GlideRecord('sn_customerservice_case');
    if (gr.get(current.sys_id)) {
        gr.state = 'Closed';
        gr.update();
    }

    template.print('<a style="font-size: 16px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; border-radius: 3px; -webkit-border-radius: 3px; -moz-border-radius: 3px; background-color: #0BB48D; border: 1px solid #0368d4; display: inline-block; padding: 5px" >Aceptar Solución</a>');
    template.print('</font></p>');


    template.print('<div style="font-size: 16px;" ><span style="font-weight: 400;">The state for </span>');
    template.print('<span style="font-weight: 700; color: #181A1F;">${number} </span>');
    template.print('<span style="font-weight: 400; ">has changed to ' + current.state.getDisplayValue() + '.</span></div>');

})(current, template, email, email_action, event);

 

 

 

(function runMailScript(current, template, email, email_action, event) {
    var url = gs.getProperty('glide.servlet.uri');
    url += 'sn_customerservice_case.do?sys_id=' + current.sys_id + '&state=Closed';
    
    // Script to update the case state
    var gr = new GlideRecord('sn_customerservice_case');
    if (gr.get(current.sys_id)) {
        gr.state = 'Closed';
        gr.update();
    }

    template.print('<a style="font-size: 16px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; border-radius: 3px; -webkit-border-radius: 3px; -moz-border-radius: 3px; background-color: #278efc; border: 1px solid #0368d4; display: inline-block; padding: 5px" href="' + url + '">Click closed case</a>');
    template.print('</font></p>');
})(current, template, email, email_action, event);

 


Here is the button that generates the email script to close the case, in this case there would have to be two buttons, one to close or open the case, this so that the applicant can accept or reject the solution to the case

AndresGc_0-1733892054605.png

 

Is there a simpler way to generate these actions to change the status of the case from the email?

If anyone knows, I would be happy to learn and provide a solution.

 

 

2 REPLIES 2

Mark Manders
Mega Patron

There are lots and lots of community posts out there that are about this topic. I listed a couple of them below. The thing to do is to create an inbound action (flow or script) that triggers on the reply that is coming in. Starts with accept = close, starts with reject = reopen. If you create the buttons so they will create the reply mail and the user only has to press 'send', it will be a 2-click accepting/rejecting of the case.

 

https://www.servicenow.com/community/itsm-forum/how-to-add-accept-and-reject-solution-options-in-not...

 

https://www.servicenow.com/community/itsm-forum/approve-and-reject-in-mail-script/m-p/2511263

 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Antoni Zahariev
Tera Guru

There is an OOB setup for this requirement:

1. Once a Case is Resolved, SN generates an Email based on the [case.resolved.for.customer] Email Template that includes the Accept and Reject email auto-reply hyperlinks and can be found on the following URL:
https://<instance_address>/now/nav/ui/classic/params/target/sysevent_email_template.do%3Fsys_id%3D59...

2. After an email with [Accept] or [Reject] Subject is received in SN, there is the OOB [Update Case via AcceptReject] Inbound Email Action that updates the Case to the relevant state and can be found on this URL:
https://<instance_name>/now/nav/ui/classic/params/target/sysevent_in_email_action.do%3Fsys_id%3D01ec... 

 

So, you can further enhance or create similar setup based on these 2 records.