Set Dashboards on User Landing Page based on roles

Ashwin Perumal1
Tera Contributor

Hello All,
I have a requirement to display dashboards on users landing page(home page) based on roles. If the logged in user has admin role then when user logs in every time then XXX dashboard should be visible by default as landing page similarly if user with itil role logs in then  for that user YYY dashboard should be visible in landing page (homepage) by default. How could I achieve this is there any system property or user preferences. Can anyone help me on it Thanks in advance.

2 ACCEPTED SOLUTIONS

Iraj Shaikh
Mega Sage
Mega Sage

Hi @Ashwin Perumal1 

1. Create a UI page:

 

  • Navigate to System UI > UI Pages.
  • Click "New" to create a new UI Page.
  • Fill in the fields:
    • Name: Enter a unique name for the UI Page (e.g., "RoleBasedRedirect").
    • HTML: Enter the following HTML and JavaScript code:
    • Please ensure that you replace 'sys_id_of_XXX_dashboard' and 'sys_id_of_YYY_dashboard' with the actual sys_ids of the dashboards you have created for the admin and ITIL roles, respectively.

 

<html>
<head>
    <title>Redirecting...</title>
    <script type="text/javascript">
        addLoadEvent(function() {
            var userRoles = '${gs.getUser().getRoles()}'.split(',');
            var redirectUrl = '';

            // Replace with the actual sys_id of the dashboards
            var adminDashboardSysId = 'sys_id_of_XXX_dashboard';
            var itilDashboardSysId = 'sys_id_of_YYY_dashboard';

            if (userRoles.includes('admin')) {
                redirectUrl = '/$pa_dashboard.do?sysparm_dashboard=' + adminDashboardSysId;
            } else if (userRoles.includes('itil')) {
                redirectUrl = '/$pa_dashboard.do?sysparm_dashboard=' + itilDashboardSysId;
            } else {
                // Default redirection for users without the admin or itil role
                redirectUrl = 'home_splash.do?sysparm_direct=true';
            }

            // Perform the redirection
            window.location.href = redirectUrl;
        });
    </script>
</head>
<body>
    <p>Redirecting, please wait...</p>
</body>
</html>

 


While saving the UI page, you will see a pop-up window as shown below. You can select 'public' and click ok.

IrajShaikh_0-1704633356060.png
By assigning the "public" role, you ensure that all users who have logged in can be redirected appropriately based on their roles.

If you want to restrict access to the UI Page to only certain roles (which is not typical for a login redirection page), you can select those specific roles instead. However, in this case, since the UI Page is meant to be accessed by any user post-login, the "public" role is the appropriate choice.


2. Set the glide.login.home Property:

  • Navigate to System Properties > All Properties.
  • Search for the property glide.login.home.
  • Set the value to the URL of the UI Page you created (e.g., ui_page.do?sys_id=your_ui_page_sys_id).
  • Save the changes.

Replace the sys id with the sys id of the UI page that you have created above.

IrajShaikh_1-1704633937177.png

 

Please mark this response as correct or helpful if it assisted you with your question.



 

View solution in original post

Hi Ashwin,

 

In order to prevent itil users from redirecting to service operations workspace. Please follow steps from servicenow documentation here

 

Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

9 REPLIES 9

Iraj Shaikh
Mega Sage
Mega Sage

Hi @Ashwin Perumal1 

1. Create a UI page:

 

  • Navigate to System UI > UI Pages.
  • Click "New" to create a new UI Page.
  • Fill in the fields:
    • Name: Enter a unique name for the UI Page (e.g., "RoleBasedRedirect").
    • HTML: Enter the following HTML and JavaScript code:
    • Please ensure that you replace 'sys_id_of_XXX_dashboard' and 'sys_id_of_YYY_dashboard' with the actual sys_ids of the dashboards you have created for the admin and ITIL roles, respectively.

 

<html>
<head>
    <title>Redirecting...</title>
    <script type="text/javascript">
        addLoadEvent(function() {
            var userRoles = '${gs.getUser().getRoles()}'.split(',');
            var redirectUrl = '';

            // Replace with the actual sys_id of the dashboards
            var adminDashboardSysId = 'sys_id_of_XXX_dashboard';
            var itilDashboardSysId = 'sys_id_of_YYY_dashboard';

            if (userRoles.includes('admin')) {
                redirectUrl = '/$pa_dashboard.do?sysparm_dashboard=' + adminDashboardSysId;
            } else if (userRoles.includes('itil')) {
                redirectUrl = '/$pa_dashboard.do?sysparm_dashboard=' + itilDashboardSysId;
            } else {
                // Default redirection for users without the admin or itil role
                redirectUrl = 'home_splash.do?sysparm_direct=true';
            }

            // Perform the redirection
            window.location.href = redirectUrl;
        });
    </script>
</head>
<body>
    <p>Redirecting, please wait...</p>
</body>
</html>

 


While saving the UI page, you will see a pop-up window as shown below. You can select 'public' and click ok.

IrajShaikh_0-1704633356060.png
By assigning the "public" role, you ensure that all users who have logged in can be redirected appropriately based on their roles.

If you want to restrict access to the UI Page to only certain roles (which is not typical for a login redirection page), you can select those specific roles instead. However, in this case, since the UI Page is meant to be accessed by any user post-login, the "public" role is the appropriate choice.


2. Set the glide.login.home Property:

  • Navigate to System Properties > All Properties.
  • Search for the property glide.login.home.
  • Set the value to the URL of the UI Page you created (e.g., ui_page.do?sys_id=your_ui_page_sys_id).
  • Save the changes.

Replace the sys id with the sys id of the UI page that you have created above.

IrajShaikh_1-1704633937177.png

 

Please mark this response as correct or helpful if it assisted you with your question.



 

Hi Shaikh,
I have followed the steps what u did and replaced the sys_id alone but its not working fine.No change on dahboard based on roles.

Hi @Ashwin Perumal1 

Did you replace the sys_id in UI page HTML code as well as system property?
It's working as expected in my PDI.
Try logging out and logging in again.

Hi Shaikh,
I did changes which u mentioned and I tested by creating  a new admin and ITIL user. For admin user its redirecting to the dashboard as per script but for ITIL user is redirects to Service Operations Landing page only. Its nor reflecting to dashboard.Can u help me on it.