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

Sagar Pagar
Tera Patron

Hi @Abigail,

You have to use the gliderecrdObject.setWorkflow(false); method of GlideRecord.

When you call setWorkflow(false), the business rules get skipped and disabled.

 

For reference: https://www.servicenow.com/community/developer-forum/what-is-the-use-of-setworkflow-false-scoped-gli... 

 

Thanks,

Sagar Pagar

The world works with ServiceNow

Hello i just need to stop a business rule in the activity, this will stop all the business rules trigger on the workflow? or just the one on the activity of the workflow

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

Amitra Bhunia
Tera Expert

Hi Abigail,

 

Why cannot you provide a suitable condition for your business rule so that it will not run for your situation? Your problem statement is missing bellow details:

1. What is the action of the BR and when it runs?

2. Why is this BR restricting you not to approve the record?

Thanks & Regards,

Amitra Bhuia