Show multiple hyperlinks in an email notification using email script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 05:45 AM - edited 10-31-2023 08:47 AM
Hi all,
I have a requirement where the due hr tasks are shown to a specific user via email notification. The links to the tasks need to be displayed in email notification line wise.
This is the script that i tried. I want to push the links into array and show it in the email, can someone give me a lead on how to proceed? I am blocked.
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
//cur_date refers to Current date
var cur_date = new Date().toISOString().split('T')[0];
var incLink = '';
var e_s_date = current.parent.ref_sn_hr_core_case.subject_person_hr_profile.employment_start_date;
//e_s_date refers to employment start date
if (e_s_date <= cur_date) {
if (current.parent.hr_service.name != "Onboarding") {
incLink = 'env?id=hrm_ticket_page&table=sn_hr_core_case&sys_id=' + current.parent.parent.sys_id;
} else {
incLink = 'env?id=hrm_ticket_page&table=sn_hr_core_case&sys_id=' + current.parent.sys_id;
}
} else {
if (current.parent.hr_service.name != "Onboarding") {
incLink = 'env?id=hrm_ticket_page&table=sn_hr_core_case&sys_id=' + current.parent.parent.sys_id;
} else {
incLink = 'env?id=hrm_ticket_page&table=sn_hr_core_case&sys_id=' + current.parent.sys_id;
}
}
template.print('incLink');
})(current, template, email, email_action, event);
Thank you in advance!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 05:55 AM
notification is on which table?
you are comparing dates in wrong manner
in this query what's present in the variable hrservice?
task.addQuery('parent.hr_service.name',hrservice);
why are you dot walking twice? current.parent.parent.sys_id
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 08:48 AM - edited 10-31-2023 08:54 AM
Hi @Ankur Bawiskar I have added that step by mistake, now I have removed it. The dates are working fine. I am stuck at pushing the links into array. and it is ion hr case table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 08:59 AM
notification is on HR case then you need not dot walk
also why to push links to array? you have if else condition
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 09:29 AM
HI @KSLN SAHITHI ,
I trust your doing fine.
Please refer the below code.
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
//cur_date refers to Current date
var cur_date = new Date().toISOString().split('T')[0];
var linksArray = []; // Array to store the links
// Your conditions to generate the links
var e_s_date = current.parent.ref_sn_hr_core_case.subject_person_hr_profile.employment_start_date; //e_s_date refers to employment start date
function generateLink() {
var link;
if (e_s_date <= cur_date) {
if (current.parent.hr_service.name != "Onboarding") {
link = 'env?id=hrm_ticket_page&table=sn_hr_core_case&sys_id=' + current.parent.parent.sys_id;
} else {
link = 'env?id=hrm_ticket_page&table=sn_hr_core_case&sys_id=' + current.parent.sys_id;
}
} else {
if (current.parent.hr_service.name != "Onboarding") {
link = 'env?id=hrm_ticket_page&table=sn_hr_core_case&sys_id=' + current
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi