GROW

code

Business rule without condition

This issue is found automatically by CODA.
Time to fix: 01h 30min

What is a Business Rule?

A Business rule in ServiceNow is a piece of code that executes automatically when a specified trigger occurs, and is used to automate processes and enforce business logic within the ServiceNow platform. Business rules can be written in JavaScript and triggered by a variety of events, such as when a record is created, updated, or deleted, or when a user performs a specific action.

They can be applied to a wide range of ServiceNow modules and are used to improve the efficiency and accuracy of processes within an organization by automating routine tasks and enforcing consistent data practices.

Why is this an issue?

Using a business rule without a condition can cause the rule to be triggered every time the specified event occurs, regardless of whether it is necessary or relevant. This can lead to unnecessary processing and resource usage.

For example, if a business rule is triggered every time a record is created or updated, and the rule performs a time-consuming or resource-intensive action, this could slow down the system and impact performance.

From an environmental perspective, business rules without conditions can also be harmful. They can cause a system to perform unnecessary actions, leading to increased resource consumption and negative impacts on the environment, such as carbon emissions. To create more efficient and sustainable software, it is important to ensure that business rules are only triggered when necessary.

A example of this, would be:

1
2
3
4
5
// This business rule is triggered every time a record is created or updated
function executeRule(current, previous) {
  // Perform a time-consuming or resource-intensive action
  // This action will be performed every time a record is created or updated, regardless of whether it is necessary or relevant
})(current, previous);

How do I fix it?

It is generally best practice to include conditions in business rules to ensure that they are only executed when necessary. For example, the following step by step demonstrates how to include a condition in the business rule to only execute the action when certain conditions are met:

  1. In the Filter Navigator, search for Business Rules under System Defition and click New.

  2. After selecting the Table, check the Advanced box.

  3. From the When to run list, check the Insert, or Update boxes, and select a When field.

  4. You can customize the conditions under which your business rule will run in the Filter Conditions section.

This allows you to specify when the rule should be triggered, based on the values of certain fields or other conditions.