Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How To Prevent Business Rule Recursive Looping When Adding a Counter Field

jmiskey
Kilo Sage

We have a situation where a team needs to report on how many times their Incidents have been reassigned.  So, I have added a custom field to the Incident table named u_assignment_group_count.  I am now working on a Business Rule to maintain that counter.

 

Here are the conditions on which that new field should be updated:

- Category is "Workday"

- Assignment Group field value is changed/updated

 

It should NOT run if fields other than the Assignment Group are changed (and the Assignment Group field remains the same).

 

So, here is how I set up the conditions:

jmiskey_0-1742924622929.png

 

And then I created script on the Advanced tab to increment the new field by 1, like this:

jmiskey_1-1742924691813.png

 

However, when I submit a record, and try to change the Assignment Group, ServiceNow just hangs, and never finished update unless I click "Cancel" on the timer counter that pops up.  I think it is getting caught in a recursive loop.  If I disable the rule, it updates immediately with no issue.  So I suspect their is an issue with how I set up the Business Rule.

 

How can I adjust my Business Rule to work the way I want it to, and not hang up?

 

Thanks

 

 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

You don't need to do a GlideRecord in a BR to lookup the current record - just use 'current.field_name' to get or set a value.  You should also do this before Update, and remove the update() line.  Since you didn't mention it, are you aware of the reassignment_count field that is already doing this?

View solution in original post

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

You don't need to do a GlideRecord in a BR to lookup the current record - just use 'current.field_name' to get or set a value.  You should also do this before Update, and remove the update() line.  Since you didn't mention it, are you aware of the reassignment_count field that is already doing this?

No, I was not aware of that field!  That is awesome!  That is exactly what I need.

I guess I don't need this Business Rule after all.

 

Thank you very much!

Chaitanya ILCR
Mega Patron

Hi @jmiskey ,

if (current.assignment_group.changes() && current.assignment_group) {
    current.u_assignment_group_count += 1;
}

make it a Before insert/update BR with above script .

isn't this functionality already exist with task level with reassignment_count field?
you want to track the changes of workday category separately is it?

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya