Use of function calling within a Business rule

Anish Reghu
Kilo Sage
Kilo Sage

Dear All,

Below is the screenshot of the OOTB BR - mark_closed on incident table. Can someone explain the need of invoking a function which is contained in the BR itself?

 

Can this function setClosureFields() be accessed from some other tools? Is that why it is made to contain in a function?

find_real_file.png

NOTE - I am learning ServiceNow development, please excuse stupidity in my examples and questions if any and help.

1 ACCEPTED SOLUTION

Sagar Pagar
Tera Patron

Hello Anish,

 

The code/script in a business rule script inside a function provide the function to limit the visibility, or scope, of objects. When code is not enclosed in a function, variables and other objects are available to all other server-side scripts. This availability can lead to unexpected consequences that are difficult to troubleshoot.

 

Refer this link for more details- Business Rules Best Practices

 

Hope this will help you.

Regards,

Sagar Pagar

The world works with ServiceNow

View solution in original post

2 REPLIES 2

Liyakhat2
Tera Expert

Hello,

 

This Business rule runs in action when the incident state chances to close or cancelled

 

it changes the other fields ==> active to false it populates==> closed by and closed at fields if they are empty and it alse calculates business duration==> by taking opened at and closed at field values

Sagar Pagar
Tera Patron

Hello Anish,

 

The code/script in a business rule script inside a function provide the function to limit the visibility, or scope, of objects. When code is not enclosed in a function, variables and other objects are available to all other server-side scripts. This availability can lead to unexpected consequences that are difficult to troubleshoot.

 

Refer this link for more details- Business Rules Best Practices

 

Hope this will help you.

Regards,

Sagar Pagar

The world works with ServiceNow