Update incident status from the body of the email

shiki
Tera Contributor

We would like to incorporate a process into the body of the email created by the notification that updates the status of the incident so that when the recipient clicks a button within the body of the email, the status of the incident is changed to "confirmed" or something similar. Any advice would be appreciated.

1 ACCEPTED SOLUTION

Vishal Birajdar
Giga Sage

Hello @shiki ,

 

There is one way to do this.

I'm not sure if this helps you or not but please check.

Assuming , you have written notification on incident table 

 

Step 1 : Create Email script

here I have created custom link which will redirect to incident record.

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,/* Optional EmailOutbound */email, /* Optional GlideRecord */ email_action,

    /* Optional GlideRecord */event) {

    var sys_id = current.getUniqueValue(); // we will get the sys_id of incident we will use in below link
    template.print('<a href="' + gs.getProperty('glide.servlet.uri') + 'incident.do?sys_id=' + sys_id + '&request_type=email_link' + '&state=Resolved' + '">' + 'Update' + '</a>');

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


VishalBirajdar7_0-1694067437059.png

 

 

Step 2 : Call this Email script in Notification body

 

${mail_script:Email_link}

VishalBirajdar7_1-1694067732357.png

 

Step 3 : Create onLoad client script on incident form

Here I have set the State to Resolved

 

function onLoad() {

    //get URL
    var gUrl = top.location.href;

    /* check if link contains "email_link" string -
    so only run this script if incident is updated by link */

    if (gUrl.toString().includes('email_link')) {

        //get the State value from link
        var getState = gUrl.split('&')[2].split('=')[1];

        g_form.addInfoMessage('State=' + getState);

        /* update the form */
        if (getState == "Resolved") {

            g_form.setValue('state', 6);
            g_form.setValue('close_code', 'Known error');
            g_form.setValue('close_notes', 'Test');
            g_form.save();
        }
    }

}

 

Output : 

When I click on "Update" 

VishalBirajdar7_2-1694067822757.png

 

It will redirect to incident form and will update the state to resolved, resolution code and notes as per onLoad script

 

VishalBirajdar7_3-1694068033357.png

 

 

Have a try...!!

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

6 REPLIES 6

jonsan09
Giga Sage
Giga Sage

You can try setting up a button/link in the notitcation. You'll want a mailto link that creates a reply and appends something like 'confirmed' to the subject line of the reply email. Then with that you create a custom inbound action to update the incident record. You can reference the docs on exambles on writing inbound actions: https://docs.servicenow.com/bundle/tokyo-servicenow-platform/page/administer/notification/reference/...

shiki
Tera Contributor

@jonsan09 

thank you for your reply.
I understand that the receive action by receiving a reply from the recipient updates the status of the incident.
By the way, is it still difficult to update the incident status with just one action (button click) by the recipient?

jonsan09
Giga Sage
Giga Sage

I don't believe there is a way to update a record directly from an email notification click. You might want to look at other notifcation other avenues for notifcations that allow updating records with a single click like a Slack/Teams notifcation

shiki
Tera Contributor

Thank you for your reply.

Let's consider the method.