Redirect user to portal based on Role.

DS14
Tera Contributor

Hi Team,

 

   We have created custom scoped App along with custom portal, where we want a user who has custom_role should auto redirect to custom portal instead of native view.

we do not want to touch 'SPEntryPage' global scope script and 'glide.entry.loggedin.page_es' sys_property.

 

Is there any other way to achieve it making changes within custom scope App only?

 

Thanks In Advanced !!

3 REPLIES 3

AyushKumarM
Mega Guru

Hi @DS14 ,

  1. Create a Global Client Script in your scoped app.

  2. Script logic:

     
    function redirectCustomRole() { var ga = new GlideAjax('CustomRedirectUtils'); // Scoped Script Include ga.addParam('sysparm_name', 'checkRoleAndRedirect'); ga.getXMLAnswer(function(response) { if (response == 'true') { window.location = '/sp?id=custom_portal'; } }); } redirectCustomRole();
  3. Script Include CustomRedirectUtils (in your scoped app) checks role:

     
    var CustomRedirectUtils = Class.create(); CustomRedirectUtils.prototype = { initialize: function() {}, checkRoleAndRedirect: function() { return gs.getUser().hasRole('custom_role') ? 'true' : 'false'; }, type: 'CustomRedirectUtils' };

    If this answer worked, please mark it as the solution. A helpful mark is also appreciated—it helps others in the community.

    Thanks and Regards,

    Ayush

     

RaghavSh
Kilo Patron

@DS14 SPEntryPage and system property are the best and recommended ways to do this.

 

1. Global client scripts are not recommended.

2. Global UI page will land you in issues, have seen in multiple implementations.

 

My recommendation would be to go with SPEntryPage SI and system property.


Please mark the answer correct/helpful accordingly.


Raghav
MVP 2023
LinkedIn

Ankur Bawiskar
Tera Patron
Tera Patron

@DS14 

I will recommend updating that OOTB Script Include for your requirement

OR

you can use UI script in your scope and check which link user is navigating and what role that person has

But you will have to run that UI script on each page which is unnecessary causing performance issue.

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