User Restriction by using Business Rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2022 02:27 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2022 02:32 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2022 04:25 AM
Hi
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;
}
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);
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
Regards,
Shloke