Double addition in Before Business Rule

lonesoac01
Giga Guru

Hello all,

 

I have a Before business rule that is adding to an integer field twice.  Here is the code:

current.u_rejection_count = current.u_rejection_count + 1;

As you can see, the intent is just to add one to whatever number was originally in the field.  It should be yielding results such as:

First rejection:

   0 (default value) + 1 = 1

 

Second rejection:

 1 + 1 = 2

 

etc.

 

What is happening is:

First rejection:

   0 (default value) + 1 = 1

   1 + 1 = 2

 

Second rejection:

   2 + 1 = 3

   3 + 1 = 4

 

My intuition is telling me that somehow another BR is causing this, but I am not sure.  What am I missing?

7 REPLIES 7

Amit Gujarathi
Giga Sage
Giga Sage

HI @lonesoac01 ,
I trust you are doing great.
You can try debugging the BR.

  • ou can use the gs.info() method to add debugging statements within your BR to get more insights into when and how it’s being executed.

Here is a revised version of your code with debugging statements:

(function executeRule(current, previous /*null when async*/) {

    // Debugging: Log the current value of u_rejection_count
    gs.info("Before BR: u_rejection_count = " + current.u_rejection_count);
    
    current.u_rejection_count = current.u_rejection_count + 1;
    
    // Debugging: Log the updated value of u_rejection_count
    gs.info("After BR: u_rejection_count = " + current.u_rejection_count);

})(current, previous);

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



lonesoac01
Giga Guru

Hello all,

 

An update on the situation.  I think I might have found a correlation between the running of the business rule twice and a related list.  I am seeing a rejection count of 3 and I am seeing a total of three rejections in the metrics related list.  I only rejected the request twice.

Screenshot 2023-11-01 094253.png

I went into the Metric definition, and it seems to be watching the Approval field.  Whatever is going on, it is clearly happening on the change_request table.

 

Screenshot 2023-11-01 095503.png