- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on ‎07-31-2024 10:40 PM
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
- Navigate to Business Rules table and proceed to create a new rule.
- Set the values as follows -
- Name - anything
- Table - Incident [incident]
- Advanced - true
- When - before
- Update - true
- Filter Conditions - Work notes changes
3. Under the 'Advanced' tab, the configuration should look something like below.
- Condition -
current['work_notes'].indexOf('DoNotCopy') == -1
- Script -
- Copyable version of the script can be found here.
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.
- 3,021 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Saura Sambit , We are facing the same issue in integration with Azure Devops. We have used REST message and scripted REST calls to make this integration. Work notes are getting duplicated. Can you help me how to avoid this? Thank you in advance.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Saura Sambit
It's working fine parent to child and child to parent.
Is it possible for all child incidents under the same parent incident to view each other's work notes, and if so, how can this be implemented?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Is this possible for CSM integration with Incident management, syncing the Case worknotes to INC worknotes and INC worknotes to case worknotes.
Also Case additional comments to INC add comments, and INC add comments to Case additional comments?