There is a way to stop a business rule and not workflow with a background script

Abigail
Tera Expert

A have a problem with a change that is not letting me approve it and seems that the issue is a business rule that is running, I'm running a background script just to approve this but I want to know if it is a way to stop the business rule only and let running the workflow?

1 ACCEPTED SOLUTION

Hi @Abigail,

Yes. this will stop all business rules for the time.

 

If you want to disable specific business rule:

  1.  You can disable it manually for the time and make it active later.
  2. You can disable using below scripts before your scripts and make it active after successful script execution.

 

// Disbale businss rule scritps
var business_rule = new GlideRecord('sys_script');
business_rule.addEncoddedQuery("sys_id=business_rule_sys_id");
business_rule.query();
if(business_rule.next()){
business_rule.active = false;
business_rule.autoSysFields(false);
business_rule.update();
}

// Enable businss rule scritps
var business_rule = new GlideRecord('sys_script');
business_rule.addEncoddedQuery("sys_id=business_rule_sys_id");
business_rule.query();
if(business_rule.next()){
business_rule.active = true;
business_rule.autoSysFields(false);
business_rule.update();
}

 

 

Thanks,

Sagar Pagar

The world works with ServiceNow

View solution in original post

6 REPLIES 6

Jaspal Singh
Mega Patron
Mega Patron

Hi,

I guess you are trying to change state value for change? If so, there is an OOB BR that is responsible for state model & thus the case. You can use setWorkFlow() as suggested in comments before. Alternatively, the BR name will be displyaed when you execute the script in Background & thus can disable (not recommended) for the script execution & enable again.

Shreya Wani
Tera Guru
Tera Guru

Hi @Abigail,

 

- Business Rules will run for operations done in scripts, just like any other insert/update/delete.

They could do unexpected things and might make the system slow.

 

- To stop this, use the below method in your script to avoid triggering any BR on the table being updated. It disables the running of business rules that might normally be triggered by subsequent actions.

obj.setWorkflow(false);

 

- Additionally, you can use the below method in your script to disable the update to the system fields of the table. For example sys_updated_by, sys_updated_on, sys_mod_count, sys_created_by, and sys_created_on.

obj.autoSysFields(false);

 

You can refer to the below KB article for more information.

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0780755

 

If you feel that I have assisted you in any manner, please mark my comment as helpful/correct.

 

Thanks,

Shreya