SPEntryPage: redirect to Service Portal by user role

stryker129
Mega Guru

Hi,

Here is a SPEntryPage Script Include snippet:

if (user.hasRoles() && user.getFullName() != "System Administrator" && user.hasRole('x_11111_notes.service portal')){

              //      

} else if (user.hasRoles() && !redirectURL && !isServicePortalURL)

    return;

and I would like to redirect users with role "x_11111_notes.service portal" to Service Portal homepage.

Looks like 1st IF condition doesn't work 'cause I created user with admin roles in system table Users - it also redirects to Service Portal Page. It's just because of newly create admin user is also has 'x_11111_notes.service portal'.

Can anyone advice where I am wrong? Is there any workaround?

Thanks.

1 ACCEPTED SOLUTION

Jon Barnes
Kilo Sage

an admin user will always return true for gs.hasRole(...) no matter what role you pass in there. So for your first if condition to work and to exclude admins, you need something like this:



  1. if (gs.hasRoles() && !gs.hasRole('admin') && gs.hasRole('x_11111_notes.service portal')) {  


I put gs here instead of "user" but I don't know what you have set user variable to, so that may be fine.


View solution in original post

7 REPLIES 7

Stephen Farrar
ServiceNow Employee
ServiceNow Employee

Hi Ivan,



It mostly looks ok script wise.



Perhaps you could try splitting up that if check in to nested statements with log statements in between so you can see where it's matching/not matching.



Cheers,


Stephen


Jon Barnes
Kilo Sage

an admin user will always return true for gs.hasRole(...) no matter what role you pass in there. So for your first if condition to work and to exclude admins, you need something like this:



  1. if (gs.hasRoles() && !gs.hasRole('admin') && gs.hasRole('x_11111_notes.service portal')) {  


I put gs here instead of "user" but I don't know what you have set user variable to, so that may be fine.


Hi Jonathan,



I have a requirement.


I want to redirect the enduser to SP depending on their respective domain.As the environment is Multi-tenant?


This will be very easy.


If domain separation is activated then include the SP table.  


Please follow the below link to apply domain separation on the sp_portal table.



https://docs.servicenow.com/bundle/istanbul-servicenow-platform/page/administer/company-and-domain-s...


In Portal Page also you can define the domain so that it will appear for the specific user of a specific domain.


That will help you sure because I also had a similar requirement.