- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2023 06:43 PM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2023 11:28 PM - edited 09-06-2023 11:30 PM
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);
Step 2 : Call this Email script in Notification body
${mail_script:Email_link}
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"
It will redirect to incident form and will update the state to resolved, resolution code and notes as per onLoad script
Have a try...!!
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2023 11:28 PM - edited 09-06-2023 11:30 PM
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);
Step 2 : Call this Email script in Notification body
${mail_script:Email_link}
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"
It will redirect to incident form and will update the state to resolved, resolution code and notes as per onLoad script
Have a try...!!
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2023 12:00 AM
thank you for the advice!
I will implement it and check it.