Restrict a user with test_role from browsing /now/nav/ui/home.

kenny_estrella
Tera Expert

I have this complicated requirement. I need to restrict a user with a certain role, test_role from browsing using /now/nav/ui/home. What I mean is, I have a PDI https://dev201638.service-now/, I want to restrict this user from going to the browser and directly accessing /now/nav/ui/home by making this as url, https://dev201638.service-now/nav/ui/home at the browser. When this user does it, he needs to be redirected to the /esc page instead.

I tried using UI Script with this code below

 

 

addLoadEvent(function() {
    console.log('THIS CODE RUNS');
    if(g_user.hasRole('test_role') && document.URL.indexOf('/now/nav/ui/home') != -1) {
        window.location='/esc';
    }
    else {return}
});

 

 

This code does not work because when we directly access /now/nav/ui/home, the page loads, and the UI Script is ignored. As you can see in the code, I added a console.log() which runs when you click any link(s) within the PDI, like accessing the Incident table, or refreshing the current UI Script in the browser. 

Is this requirement solvable? Please help me, thanks.

 

1 REPLY 1

Rupekumar
Tera Contributor

I alsa have same requirement