Double addition in Before Business Rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 07:43 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 07:55 AM
Hello lonesoac1,
I assume that the condition that triggers that BR is that you update any field when you do a rejection. Try this Business rule on after, instead on before and also, be more restricted in terms on conditions to control exactly when you want to trigger this BR.
☆ Community Rising Star 22, 23 & 24 ☆
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 07:58 AM
Query the BR table, for table=[table name in your BR], and Script contains 'u_rejection_count'. Review those.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 08:07 AM - edited 10-31-2023 08:09 AM
Your intuition is correct. The transaction is happening twice and that is why you see this.
Most likely cause: Check if there is any other BR that has current.update() on it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 08:48 AM
Try:
current.u_rejection_count = previous.u_rejection_count + 1;