ServiceNow Security: How to Limit Access Based on User Roles Using Client Scripts in Four Steps

BillMartin
Mega Sage

I have created this article to help implementors and developers alike to identify how to limit and control access using ServiceNow Client Scripts.

 

ServiceNow Client Scripts is a very powerful tool of ServiceNow. It has broad capabilities that fully utilize the ServiceNow out-of-the-box libraries like g_form, g_user objects, and of course the JavaScript framework.

 

Some of the features it can do are the following:

 

  • make fields hidden or visible
  • make fields read only or writable
  • make fields optional or mandatory based on the user's role
  • set the value in one field based on the value in other fields
  • modify the options in a choice list based on a user's role
  • display messages based on a value in a field

To give you a better picture, let us drill down to the four steps:

 

Step one:

You can limit what an end user can see or view based on the role/group you created under user administration.

Step two:

Starting from the base access - no access, read only, edit , create and finally delete. - the granuality will differ based on the governance structure of the business.

Step three:

Utilize the g_user.hasRoleExactly('name of role') - this code identifies the currently logged in user has the role explicitly assigned.

Step four:

Get use of the g_form object to implement governance based on step two.

 

The four steps mentioned is a guide or your first step that will give you a picture of the power of Client Script. However, including the power of JavaScript you can manipulate the elements since the ServiceNow libraries sits in a browser that allows you to also fully configure the Document Object Model (DOM)

 

To give you a picture of how Client Script Works, i created this video for your visbility and guidance.

 

Here is How: ServiceNow Scripting: How to Create Client Scripts in ServiceNow

 

Please mark as helpful if you find the article lucrative.

1 ACCEPTED SOLUTION

BillMartin
Mega Sage
2 REPLIES 2

Nikhil Bajaj9
Giga Sage

Good Explanation. Thanks for Sharing Knowledge.

Please appreciate my efforts, help and support extended to you by clicking on – “Accept as Solution”; button under my answer. It will motivate me to help others as well.
Regards,
Nikhil Bajaj

BillMartin
Mega Sage

Thanks @Nikhil Bajaj9 😊🙏