Show multiple hyperlinks in an email notification using email script

KSLN SAHITHI
Tera Expert

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!!

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@KSLN SAHITHI 

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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

@KSLN SAHITHI 

notification is on HR case then you need not dot walk

also why to push links to array? you have if else condition

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Amit Gujarathi
Giga Sage
Giga Sage

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