Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Prevent an admin from specific deletions in background script

Anton42
Tera Expert

Hello,

is it possible to prevent background script deletion of only a specific table like sys_user for admin users?

 

So, for example:

We want to prevent, that users with admin role cannot execute deletion on the sys_user table.

 

Thank you in advance.

11 REPLIES 11

RitheshB
Tera Contributor

Use "Before" Business Rule 

  1. Go to System Definition → Business Rules.
  2. Click New.
  3. Configure like this:
  • Name: Prevent sys_user deletion for admins
  • Table: sys_user
  • Advanced: Checked
  • When: Before
  • Insert/Update: Unchecked
  • Delete: Checked
  1. Condition: (Optional) – Only for admin role users:

                         gs.hasRole('admin');

  1. Script:

(function executeRule(current, previous /*null when async*/) {
    if (gs.hasRole('admin')) {
        gs.addErrorMessage("Admins are not allowed to delete users!");
        current.setAbortAction(true); // Prevent deletion
    }
})(current, previous);

 

Aditya_hublikar
Mega Sage

Hello @Anton42 ,

 

Yes this is possible via before delete business rule :

 

br1.png

 

br2.pngbr3.png

 

 

If my response helps you then mark it as helpful and accept as solution.

Regards,

Aditya,

Technical Consultant

@Aditya_hublikar 

this will stop admin from deleting user from list or form as well

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

Hello @Ankur Bawiskar ,

 

yes it will stop admin from deleting user from list or form as well 🙂.

 

how can we restrict deletion operation only for background script ?