Business Rule to inactive users based on a checkbox

Mohamed Elsayed
Tera Expert

Hi everyone,

 

I’m working on a basic logic for the Account form, where I have a True/False checkbox labeled “Customer.” My goal is to deactivate all contacts related to an account and disable their notifications when this checkbox is unchecked. Although I managed to accomplish this using the flow designer, I believe it should be done with a business rule instead. However, my attempts to create a working business rule have been unsuccessful. Any suggestions?

 

The Business Rule Details:

Table: customer_contact

When: tried before and after

 

MohamedElsayed_0-1727882872853.png

MohamedElsayed_1-1727882898025.png

Regards,

Mo

2 ACCEPTED SOLUTIONS

Sai_Charan_K
Kilo Sage

Hi @Mohamed Elsayed ,

If you could write the br on "account" table and query your "contact" table to check for account which is set to false, you can achieve this task. You just have to set the workflow and autosysfields to false and set the notification preferences to "none" to achieve this.

 

Please mark this answer as "Helpful" and "correct" if you feel this answer has helped you in anyway.

 

Thanks and Regards,

K. Sai Charan 

Sr. ServiceNow Developer 

Deloitte India

View solution in original post

Animesh Das2
Mega Sage

Hi @Mohamed Elsayed ,

 

As @Sai_Charan_K already suggested the approach for you to achieve this, I can try to create a sample BR script for you to do it easily with just adjusting the field names/values according to your tables' structure.

 

BR:

Write an 'After' BR on 'account' table for 'Update' operation, WHEN the 'customer' value changes to 'false'.

 

In the Script (Under 'Advanced' tab),

var grCust = new GlideRecord('customer_contact');
grCust.addQuery('<account field name>', current.sys_id);
grCust.query();
while(grCust.next()){
grCust.active = false;
grCust.notification = 'disabled';
grCust.update();
}

 

Please check if this helps you to achieve the solution, or share if you face any challenges.

 

If this address your question, please mark this response correct by clicking on Accept as Solution and/or Kudos.

You may mark this helpful as well if it helps you.

Thanks, 

Animesh Das

View solution in original post

3 REPLIES 3

Sai_Charan_K
Kilo Sage

Hi @Mohamed Elsayed ,

If you could write the br on "account" table and query your "contact" table to check for account which is set to false, you can achieve this task. You just have to set the workflow and autosysfields to false and set the notification preferences to "none" to achieve this.

 

Please mark this answer as "Helpful" and "correct" if you feel this answer has helped you in anyway.

 

Thanks and Regards,

K. Sai Charan 

Sr. ServiceNow Developer 

Deloitte India

Animesh Das2
Mega Sage

Hi @Mohamed Elsayed ,

 

As @Sai_Charan_K already suggested the approach for you to achieve this, I can try to create a sample BR script for you to do it easily with just adjusting the field names/values according to your tables' structure.

 

BR:

Write an 'After' BR on 'account' table for 'Update' operation, WHEN the 'customer' value changes to 'false'.

 

In the Script (Under 'Advanced' tab),

var grCust = new GlideRecord('customer_contact');
grCust.addQuery('<account field name>', current.sys_id);
grCust.query();
while(grCust.next()){
grCust.active = false;
grCust.notification = 'disabled';
grCust.update();
}

 

Please check if this helps you to achieve the solution, or share if you face any challenges.

 

If this address your question, please mark this response correct by clicking on Accept as Solution and/or Kudos.

You may mark this helpful as well if it helps you.

Thanks, 

Animesh Das

Mohamed Elsayed
Tera Expert

Thanks Sai_Charan_K & Animesh Das2 for your help, I tested it and it works as expected however, I might stick to the flow as I aim to avoid scripting and keep most of the configuration as low-code as possible. Considering that I am relatively new to the ServiceNow world, it would be appreciated if you check the workflow before I active and move it to production,

MohamedElsayed_0-1727947390525.png

MohamedElsayed_1-1727947426485.pngMohamedElsayed_2-1727947449146.pngMohamedElsayed_3-1727947469727.png

MohamedElsayed_4-1727947497668.png

 

Regards,

Mo