Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Ramya V
Kilo Sage

Redirect Approvers Based on Role (Workspace vs ESC)


Description

In some scenarios, approvers receive email notifications with links to review approvals. However, based on their roles, users should be redirected to different interfaces.

Users with the ITIL role should be directed to Agent Workspace, while users without this role should be redirected to the Employee Service Center (ESC) To-Do page.

This solution ensures a better user experience by guiding users to the correct interface based on their access level.


Steps to Implement

  1. Create or update an Email Notification

  2. Add a Mail Script

  3. Use a role check to determine if the approver has the ITIL role

  4. Generate a dynamic link based on the role

  5. Print the link in the email template


Email Script

(function runMailScript(
    current,
    template,
    email,
    email_action,
    event
) {

    var isAgent = false;

    // Check if approver has ITIL role
    var roleGR = new GlideRecord('sys_user_has_role');
    roleGR.addQuery('user', current.approver);
    roleGR.addQuery('role.name', 'itil');
    roleGR.query();

    if (roleGR.hasNext()) {
        isAgent = true;
    }

    var baseUrl = gs.getProperty('glide.servlet.uri');
    var link;

    // Redirect logic
    if (isAgent) {
        link = baseUrl + 'now/cwf/agent/record/sysapproval_approver/' + current.sys_id;
    } else {
        link = baseUrl + 'esc?id=hrm_todos_page';
    }

    template.print('<a href="' + link + '" style="color:#12086f;">View Approval</a>');

})(current, template, email, email_action, event);

How It Works

  • The script queries sys_user_has_role to check if the approver has the ITIL role

  • If true → user is redirected to Agent Workspace

  • If false → user is redirected to ESC portal (To-Do page)

  • The link is dynamically generated using the instance base URL


Result

  • ITIL Users → Open approval directly in Workspace

  • Non-ITIL Users → Open approval in ESC (Portal)

  • Single notification works for both user types


Conclusion

This approach provides a clean and efficient way to handle role-based redirection in email notifications, ensuring that users always land in the correct interface for their role.

 

Version history
Last update:
an hour ago
Updated by:
Contributors