The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Redirect email notification based on role to Portal or Workspace

Rekha20
Tera Contributor

HI All,

I need to redirect HR case based on User's role to Portal or Agent workspace.

 

I created a mail script which is called in email layout, email footer is called in notification

 

Mail Script:

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */ event) {

    // Get the HR Case record
    var gr = new GlideRecord('sn_hr_core_case');
    if (gr.get(current.sys_id)) {

        // Get instance base URL
        var baseURL = gs.getProperty('glide.servlet.uri');

        // Get dynamic values
        var sysId = gr.getUniqueValue();
        //var tableName = gr.getTableName();
        var tableName = (current.sys_class_name && current.sys_class_name.toString()) || current.getTableName();
        var caseNumber = gr.number || 'HR Case';

        // Construct URLs

        var portalURL = baseURL + 'esc?id=hrm_ticket_page&table=' + tableName + '&sys_id=' + sysId;

        var workspaceURL = baseURL + 'now/hr/agent/record/' + tableName + '/' + sysId;

        // link text based on user's role
        var linkText = '';


        if (!gs.hasRole('sn_hr_core.basic')) {
            // HR Agent
            gs.info("RTIWARi "+ "Portal User")          
            linkText = '<a href="' + portalURL + '">' + caseNumber + '</a>';
           
        } else {
            gs.info("RTIWARi "+ "Non Portal User")
            // Non-HR User
           linkText = '<a href="' + workspaceURL + '">' + caseNumber + '</a>';
        }
       

        template.print('<p><strong>Case:</strong> ' + linkText + '</p>');

    }

})(current, template, email, email_action, event);
 
 
It is changing when previewing notification from notification itself but when notification triggered then workspace URL link is there in email only. Any suggestion to fix this, please?
 
Thanks,
2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Rekha20 

so basically if you have 5 email recipients and 2 are having some role then you want them to be taken to portal and other 3 to workspace?

how are you triggering the email and to whom?

check this link as well

Dynamic email links dependent on recipient role? 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Rekha20 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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