Bi-directional Journal Field Sync

Published Categorized as ServiceNow Tagged , , , ,

In the ServiceNow ecosystem, we frequently encounter the requirement to synchronise journal field entries, such as Work Notes or Additional Comments, between related task records. The most straightforward approach is to use business rules. This method works well for unidirectional synchronisation. However, when synchronisation needs to be bidirectional, duplicate journal entries begin to appear due to recurring triggers of the business rules.

Over the years, various approaches have been employed to address this issue, including the creation of custom checkbox fields, setting workflows to false, and several others. While these methods are effective, they often introduce some form of technical debt. In this article, we will explore a straightforward solution for achieving bidirectional synchronisation. Our method will not involve creating custom fields or disabling notifications and other updates by setting workflows to false.

  • Keep the below snippet in mind, we will be making use of this.
[code]<p DoNotCopy></p>[/code]

Requirement

When a Work Note is added to any Incident [incident] record,

  • copy the Work Note to the parent incident.
  • copy the Work Note to any child incidents.

Business rule configuration

  1. Navigate to Business Rules table and proceed to create a new rule.
  2. Set the values as follows –
    • Name – anything
    • Table – Incident [incident]
    • Advanced – true
    • When – before
    • Update – true
    • Filter Conditions – Work notes changes
  1. Under the ‘Advanced’ tab, the configuration should look something like below.
  • Condition –
current['work_notes'].indexOf('DoNotCopy') == -1
  • Script –

How will this stop the recurring triggers?

In line 20 of the script, before copying the work_notes, we are adding a code snippet to it.

[code]<p DoNotCopy></p>[/code]

Since it is an empty HTML block, the code snippet remains invisible when viewing the work notes directly, but it can be detected through code. Therefore, the condition field on the business rule will check for this snippet’s existence and prevent the business rule from being re-triggered.

  • Condition –
current['work_notes'].indexOf('DoNotCopy') == -1

Number of custom fields? Zero. setWorkflow(false)? Not needed.

Just keep adding a similar snippet and condition to the business rule whenever there is a need to copy journal entries automatically and there would be no duplicates.

The business rule can also run ‘after’ or ‘async’, we just have to access the journal fields like –

current.work_notes.getJournalEntry(1)

Next steps

Experiment by writing rules to copy journal entries across multiple tables, share among your peers.

1 comment

  1. very helpful, customized and optimised solution.
    Definately I will use your strategy for the same requirement.

    Thank you.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses User Verification plugin to reduce spam. See how your comment data is processed.