Any Possibilities to log when a Business Rule / Script modifies a field?

Oliver Strein
Tera Contributor

Hi all,

 

is there a possibility to log when a Business rule is modifying a field value?

 

Lets say, a Business Rule is changing the state of an Incident. 

In the Incident this modification is logged and I can see that the state got changed from a to b through "system".

But who is "system" in this case?

 

Therefor: Is there a way to document that this "change" was done through Business Rule "XYZ" ?

 

Thanks

Oliver

1 ACCEPTED SOLUTION

raj chavan
Tera Guru

Hey @Oliver Strein 
System represents actions performed by system processes, including Business Rules, Workflows, and Flows.

By default, when a Business Rule modifies a field, the change is logged as being made by "system." However, ServiceNow does not directly log which specific Business Rule performed the modification

However there is one custom approach we can use 

- Use a Custom Field to Log Changes
   Add a field (e.g., `u_modified_by_br`) to the table (like `Incident`) to store the name of the Business Rule that made the change.(You can hide this field on list )

- Update Business Rule Script  
   Modify each Business Rule to explicitly log its name when it modifies a field

 

 

 if (current.state.changes()) {
       current.u_modified_by_br = "BR_Name"; // Replace with the actual Business Rule name
   }​

 

 

 

Log Changes in the System Log
   Add a logging statement to record the Business Rule that made the change.
 
   Example:

 

 

   if (current.state.changes()) {
       gs.log("State changed by Business Rule: BR_Name", "Business Rule Tracking");
   }

 

 

 

Add Comments to Track Changes   
   If you want this information visible in the Activity Stream you can append it to the `work_notes`.

 

 

   if (current.state.changes()) {
       current.work_notes = "State changed by Business Rule: BR_Name";
   }

 

 
 
 
Kindly mark it correct and helpful if it is applicable.

Thanks,

Raj

View solution in original post

2 REPLIES 2

raj chavan
Tera Guru

Hey @Oliver Strein 
System represents actions performed by system processes, including Business Rules, Workflows, and Flows.

By default, when a Business Rule modifies a field, the change is logged as being made by "system." However, ServiceNow does not directly log which specific Business Rule performed the modification

However there is one custom approach we can use 

- Use a Custom Field to Log Changes
   Add a field (e.g., `u_modified_by_br`) to the table (like `Incident`) to store the name of the Business Rule that made the change.(You can hide this field on list )

- Update Business Rule Script  
   Modify each Business Rule to explicitly log its name when it modifies a field

 

 

 if (current.state.changes()) {
       current.u_modified_by_br = "BR_Name"; // Replace with the actual Business Rule name
   }​

 

 

 

Log Changes in the System Log
   Add a logging statement to record the Business Rule that made the change.
 
   Example:

 

 

   if (current.state.changes()) {
       gs.log("State changed by Business Rule: BR_Name", "Business Rule Tracking");
   }

 

 

 

Add Comments to Track Changes   
   If you want this information visible in the Activity Stream you can append it to the `work_notes`.

 

 

   if (current.state.changes()) {
       current.work_notes = "State changed by Business Rule: BR_Name";
   }

 

 
 
 
Kindly mark it correct and helpful if it is applicable.

Thanks,

Raj

Hi @raj chavan 
thanks for this solution. We'll give it a try. 

 

Much appreciated 

Oliver