If you've ever tried to solve this problem with one or two 'after' Business Rules that simply copy comments from one record to the other… congrats, you've discovered recursion!
Unfortunately, you've also discovered infinite loops.
If you next tried adding .setWorkflow(false) to the Business Rule that copies the field to the other record, then unfortunately you've also discovered that that breaks all the other Business Rules, notifications, and automation that should be happening.
In this article, I'm going to share two patterns for solving this problem that I think are pretty neat, clean, and effective. Both of these patterns allow you to sync journal entries between two linked records without infinite loops, without adding any fields to your tables, and without suppressing workflow.
Option 1 uses an invisible marker in the journal entry text to indicate that the update was caused by the sync process.
Option 2 is even more clever, and although it requires a tiny bit more setup (I provide the code below), it can actually work with any field(s), not just journal entries! It uses a session-scoped, record-pair-specific 'lock' to prevent the receiving Business Rule from acting on updates that were caused by the sync process.
We have a few challenges here: no .setWorkflow(false), no Task-based-table schema changes, and no ugly journal entry pollution.
Here's the scenario --
You’ve got two task-based tables that are linked.
Let's say Incident and Case.
These tables are linked in a 1:1 relationship; that is, when Incident A points to Case B, Case B always points back to Incident A, and vice versa.
(It doesn't matter if this is your exact setup or if your records are linked 1:1, this is just the example setup. This can be applied to any synced pair of records.)
There are several different ways that a 1:1 relationship could exist, and this same question could apply to two linked records in the same table, or in different tables - but just for simplicity (and clarity), let's say our setup looks like this:
Case has an Incident [u_incident] reference field.
Incident has a Case [u_case ] reference field.
When someone adds a comment to either record, you want the same comment to show up on the other record.
(You could just as well apply this logic to work_notes or any other journal field, but we'll use comments as the example.)
…and you want that to happen exactly once, not in an infinite summoning-circle that consumes your instance and eventually summons an angry DBA.
You can’t just do .setWorkflow(false) because you’re not trying to turn off automation. You’re trying to turn off recursion. You still want any other Business Rules to fire, notification emails to be sent out, etc.
I feel like I've solved this problem a thousand times, but it's always felt hacky and ugly... I don't think I've ever seen a solution that felt "clean" and performant, or that didn't make my brain itch because it just felt wrong and fragile.
Today, I've come up with two ways to solve this problem.
Both work. Both are pretty neat, clever, and clean. Both solve a problem that I feel like I've been plagued by a dozen times throughout my career, and for which I've never had a really solid, effective, clean solution - until now…
