Business Rules looping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2022 11:37 AM
Hi.
I read about not using the current.update() but I need to update another record on another table. I created 2 business rules, 1 for the incident table and other for the sn_hr_core_case table.
The business rule executes whenever the work notes changes. The issue is that it runs both at once. In an HR Case, if I post something, it doubles the work notes because it also is running the other business rule attached to the incident table. Maybe there is a better way to do this but these are the 2 business rules:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2022 12:21 PM
Hi,
You can use (for example😞
gr.setWorkflow(false);
and that will prevent additional business rules from running for that update. You'd place that right before your update() line.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2022 03:17 PM
Hello,
I just wanted to check-in as it's been about a week and see if my reply above helped guide you Correctly.
Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2022 01:10 PM
Hi SC,
I had a similar looping issue when syncing customer comments between a RITM and SCTASK and back. I ended up cleaning the journal entry and comparing it against the last comment in the target table.
I've modified my code based on your first Incident >> HR case work notes example. You should be able to modify it for the reverse logic:
(function executeRule(current, previous /*null when async*/) {
updateWorkNotes();
function updateWorkNotes() {
var parent = current.getValue("parent");
var grCase = new GlideRecord('sn_hr_core_case');
if (grCase.get(parent)) {
// Before we update the target task, we need to prevent an infinite loop by ensuring the comment that is causing this business rule to run is not the same text that was in the last comment on the target task.
//return the last journal entry for the current task and extract the journal text below the line break.
var workNote = cleanJournalEntry(current.work_notes.getJournalEntry(1));
//return the last journal entry for the target task and extract the journal text below the line break.
var trgtWorkNote = cleanJournalEntry(grCase.work_notes.getJournalEntry(1));
gs.info("(BLS) Number | {0} | source Work Notes | {1} - trgt Work Notes | {2} indexOf: {3}",[current.number,workNote,trgtWorkNote,trgtWorkNote.indexOf(workNote)]);
/***** NOTE: If the same comments are entered twice, the second journal entry will not be copied to the target task as it will match the first comment *****/
if (trgtWorkNote.indexOf(workNote) < 0) {
// OnAfter business rules cannot process comments so we need to pull from the journal
grCase.work_notes = workNote;
grCase.update();
}
}
}
/**
* Description: Cleans up the journal entry to remove timestamp, audit information and trim any white space.
* Parameters:
* @PARM1 - journalEntry (String) - Journal entry by index number i.e. current.comments.getJournalEntry(1)
* Returns: entry (String) - cleaned up journal entry with just the comment information.
*/
function cleanJournalEntry(journalEntry){
var entry = "";
if (journalEntry) {
//We need to clean-up the journal entry
//return all text after the first line break in the journal entry (first line contains timestamp and audit information).
entry = journalEntry.substr(journalEntry.indexOf('\n')+1);
entry = entry.trim(entry); //remove any whitespace before and after string
}
return entry;
}
})(current, previous);
Hope this helps
Kind regards,
Brent
Please mark reply as Helpful/Correct, if this helped resolve your issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2022 03:16 PM
Hi SC,
Just checking if any of the suggestions helped to resolve your issue? If so, please mark as correct so other community members can benefit from this information.
Brent