How to Update a table record using a link in email notification

Sree21
Tera Guru

I have a need to update KB article using a link in email notification sent to itil users. Once the user clicks on the email link, it should updated the KB article with an expiry date of (current date + 1 year). How can this be set up? Please help!

1 ACCEPTED SOLUTION

Sree21
Tera Guru

I am able to achieve this by creating a new UI page 'newUIpagename' with example code as below and using the UI page url in the email link, '<a href="https://' + instance_name + '.service-now.com/newUIpagename.do?sysparm_kb_id=' + current.sys_id + '&sysparm_action=update"' >'

HTML field:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<j:set var="jvar_kb" value="${sysparm_kb_id}" />
<g:evaluate var="jvar_unwrapped_url" jelly="true">

var kb = RP.getParameterValue('sysparm_kb_id');
var kb_action = RP.getParameterValue('sysparm_action');
var link = '';
var kb_article = new GlideRecord('kb_knowledge');
kb_article.addQuery('sys_id', "${sysparm_kb_id}");
kb_article.addQuery('workflow_state', "published");
kb_article.query();
if(kb_article.next()){
if (kb_action == "update") {
kb_article.setValue(//update the field values);
kb_article.update();
gs.addInfoMessage(kb_article.getDisplayValue() + ' is updated. Redirecting to KB Article');
}
if(kb_action == "retire") {
kb_article.setValue('workflow_state','retired');
kb_article.update();
gs.addInfoMessage(kb_article.getDisplayValue() + ' is retired. Redirecting to KB Article');
}
}
gs.setRedirect("kb_knowledge.do?sys_id=" + kb_article.sys_id);
</g:evaluate>
${gs.getMessage("Redirecting to KB article")}...
</j:jelly>

 

Client Script field:

document.location.href = "$[JS:jvar_unwrapped_url]";

View solution in original post

4 REPLIES 4

AnubhavRitolia
Mega Sage
Mega Sage

Hi @Sree21 

 

Please refer below Community Post with solution. Issue is almost same.

 

https://www.servicenow.com/community/developer-forum/how-to-create-an-email-with-the-hyperlink-that-...

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

Thank you for the reply. I am looking for a solution without using inbound action for the reply email. When the URL link on the notification is clicked, it should update the record without having to send an email reply.

Hi @Sree21 

 

Without inbound action how will the reply connect with the instance. How will Instance know that Link was Clicked.

 

I don't think its possible without inbound action or manual sets to update.

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

Sree21
Tera Guru

I am able to achieve this by creating a new UI page 'newUIpagename' with example code as below and using the UI page url in the email link, '<a href="https://' + instance_name + '.service-now.com/newUIpagename.do?sysparm_kb_id=' + current.sys_id + '&sysparm_action=update"' >'

HTML field:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<j:set var="jvar_kb" value="${sysparm_kb_id}" />
<g:evaluate var="jvar_unwrapped_url" jelly="true">

var kb = RP.getParameterValue('sysparm_kb_id');
var kb_action = RP.getParameterValue('sysparm_action');
var link = '';
var kb_article = new GlideRecord('kb_knowledge');
kb_article.addQuery('sys_id', "${sysparm_kb_id}");
kb_article.addQuery('workflow_state', "published");
kb_article.query();
if(kb_article.next()){
if (kb_action == "update") {
kb_article.setValue(//update the field values);
kb_article.update();
gs.addInfoMessage(kb_article.getDisplayValue() + ' is updated. Redirecting to KB Article');
}
if(kb_action == "retire") {
kb_article.setValue('workflow_state','retired');
kb_article.update();
gs.addInfoMessage(kb_article.getDisplayValue() + ' is retired. Redirecting to KB Article');
}
}
gs.setRedirect("kb_knowledge.do?sys_id=" + kb_article.sys_id);
</g:evaluate>
${gs.getMessage("Redirecting to KB article")}...
</j:jelly>

 

Client Script field:

document.location.href = "$[JS:jvar_unwrapped_url]";