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

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

thank you for the advice!

I will implement it and check it.