Redirect to Service Portal if the user has Business_stakeholder rule

Jesus Herrera
Tera Contributor

I'm trying to be able to validate if the user has the business_stakeholder role to send it straight to the Service Portal page and if is someone else go to the respective frontpage like admins or ITILs to the IS View and who doesn't have a role to go to the Service Portal.

 

Found another Question related to this and shows that I have to change this in the script SPEntryPage:

 

The Initialize function adding the validation of the stakeholder and setup the default page to the Service Portal.
initialize: function() {
    this.logVariables = false; // for debugging
    if (user.hasRole("business_stakeholder"))
         this.portal = "/sp/"; // Set the URL to the Service Portal
    else
        this.portal = this.getDefaultPortal(); // The URL suffix for default portal
    },

 
And Inside of the get FirstPage URL function to change the following part validating that if the user has roles and one of the roles is business_stakeholder then skip the following validation and continue with the flow of the script.
if (user.hasRoles() && !user.hasRole("business_stakeholder")) {
    if (user.hasRoles() && !redirectURL && !isServicePortalURL)
           return;
}
 
But the problem I have is because the user.hasRole return true for admins at the same time as I validate for the role I need, and keeps sending the admins to the SP too. Is there another function that only validate for the role I need? or there is a workaround about this.
1 ACCEPTED SOLUTION

I would return the initialize function to only for the portal page...  

initialize: function() {
		//this.logVariables = true;  // for debugging 
		this.logVariables = false; 
		this.portal = "/sp/";      // The URL suffix specified in the sp_portal record
},

and then check to be sure the returnURL variable is defined to this.portal.  

View solution in original post

3 REPLIES 3

d_cammack
Tera Guru

Hello Jesus,

Try just setting the admin and itil roles in the 'getFirstPageURL' section of the SPEntryPage script include, like:

if ((user.hasRole('admin') || user.hasRole('itil')) && !redirectURL && !isServicePortalURL)
			return;

Any other role should then redirect to the portal.  

It didn't work. it always go to the IS View instead of the Home Service Page

I would return the initialize function to only for the portal page...  

initialize: function() {
		//this.logVariables = true;  // for debugging 
		this.logVariables = false; 
		this.portal = "/sp/";      // The URL suffix specified in the sp_portal record
},

and then check to be sure the returnURL variable is defined to this.portal.