User Restriction by using Business Rule

Shawn33
Tera Expert

1.Create a table called 'User Restriction'

2.Create fields called user - reference, Field name, Field Value

3.Restrict the updation of the user for the user fields that are present in the user restrictions table.

--->I have created table and fileds need to write BR for this requirement,help me with BR script.

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

who is allowed to update User reference field?

Only the user which is present in that user field?

if yes then you can achieve this using field level WRITE ACL and no BR is required

Regards
Ankur

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

shloke04
Kilo Patron

Hi @Shawn 

There can be multiple approach to this scenario on how you want to handle this.

1) First option: You can make the Fields Read Only after the record is inserted so that no one can update the field values.

So for that Create a Field Level ACL on the Table "User Restrictions" and use the script as below:

if(!current.isNewRecord()){
	answer = false;
}else{
	answer =true;
}

find_real_file.png

This will make all fields as Read only for existing records. You also need to check if there are any other ACL present on the User restriction table or not which is existing and giving access then you need to update those as well to restrict it.

Second Approach: Fields remains editable but if some one tries to update or modify the field value error is thrown to them using a Business Rule.

Create a Before Update Business Rule on User Restrictions table and use the script as below:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	gs.addErrorMessage('Field updates are not allowed');
	current.setAbortAction(true);

})(current, previous);

find_real_file.png

ACL should be the preferred method, have shown you both approaches which ever you think is appropriate based on your customer scenario you can follow that.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke