Redirect user to a different page if user does not have access to a record producer

Mayank Rustagi
Tera Guru

We have impletemented a "Available For" User Criteria on a record producer. In the portal, users will not see the record producer in the catalog list. This is as expected and works perfectly.

But if users attempt to access the record producer directly thorough an external link, users that do not meet the user criteria see a blank page. This is confusing the users and they are unsure why they see a blank screen.

Is there a way that we can redirect the users to a different page if they do not meet the user criteria for a record producer?

1 ACCEPTED SOLUTION

Aman Kumar S
Kilo Patron

You can write an onload script on the record producer.

I have done to check if user has certain role or not.

You can similarly have check for certain conditions based on user criteria and if server side scripting is required you can get that from GlideAjax, and in your callback function response you can include top.window() function to redirect user to any url you want.

 

if(!g_user.hasRole("test_role")){
        var url = "https://community.servicenow.com/communityid=community_user_profile&user=33b26047db00441823f4a345ca96192a";
        
        top.window.open(url, "_blank");
    }

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

Best Regards
Aman Kumar

View solution in original post

3 REPLIES 3

Aman Kumar S
Kilo Patron

You can write an onload script on the record producer.

I have done to check if user has certain role or not.

You can similarly have check for certain conditions based on user criteria and if server side scripting is required you can get that from GlideAjax, and in your callback function response you can include top.window() function to redirect user to any url you want.

 

if(!g_user.hasRole("test_role")){
        var url = "https://community.servicenow.com/communityid=community_user_profile&user=33b26047db00441823f4a345ca96192a";
        
        top.window.open(url, "_blank");
    }

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

Best Regards
Aman Kumar

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

You can take the approach mentioned by Aman i.e. onLoad client script + GlideAjax

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

SumanthDosapati
Mega Sage
Mega Sage

Hi,

You can use the method suggested by Aman using client script with glide ajax and script include.

Or

Try creating one small global UI script as below.

 

autoRedirect(function() {   

         if (!g_user.hasRole('role_here') && document.URL.indexOf('sys_id of the record producer') != -1) 
		 {   

                   window.location = 'Give your url here';   

         }  
});

 

Mark as correct and helpful if it solved your query.

 

Regards,

Sumanth