# How to prevent infinite loop on rule triggered by formula field

**URL:** <https://community.fibery.io/t/how-to-prevent-infinite-loop-on-rule-triggered-by-formula-field/6137>\
**Category:** Get Help\
**Created:** [April 30, 2024, 6:30pm UTC](https://community.fibery.io/t/how-to-prevent-infinite-loop-on-rule-triggered-by-formula-field/6137 "2024-04-30T18:30:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![interr0bangr](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/interr0bangr/32/8089_2.png) [@interr0bangr](https://community.fibery.io/u/interr0bangr)\
**Post date:** [April 30, 2024, 6:30pm UTC](https://community.fibery.io/t/how-to-prevent-infinite-loop-on-rule-triggered-by-formula-field/6137/1 "2024-04-30T18:30:57Z")

</div>

I’m once again running into issues with loop detection in rules and humbly asking for some help.

Basically, I want to calculate the days in a sprint, and then create a “Day” entity for each of those days.

I thought a “Days Missing” \> 0 filter would be enough to prevent the loop, but it’s still failing.

**Here’s my rule logic:**

 ![Fibery-Database-Fibery (1)](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/7/7dc5471c0c0051f4b93d08c2a39b9b9769ae96db.jpeg)

**Here’s the logic for for the formulas:**

 ![Week-25-Jun-17-20-2024-G-—-Sprint-Fibery (1)](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/1/18653466e3b8fd9cdac29999e537bd19902aabb9.jpeg)  
 ![Week-25-Jun-17-20-2024-G-—-Sprint-Fibery (2)](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/7/7f11ea4c8b0be908c0500d890d6a3efb98b28868.jpeg)  
 ![Week-25-Jun-17-20-2024-G-—-Sprint-Fibery (3)](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/c/c462252bb48204981540a5df6f316e75d7a4358f.jpeg)

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [April 30, 2024, 7:06pm UTC](https://community.fibery.io/t/how-to-prevent-infinite-loop-on-rule-triggered-by-formula-field/6137/2 "2024-04-30T19:06:32Z")

</div>

You won’t be able to avoid a loop using this method, since the Days Missing value will get changed every time a new Day is added (which happens when the automation runs).  
If you want to create a batch of entities, where the number of entities in the batch is dynamic, the only safe way to avoid a loop is to use a script.  
If your sprints are always the same length (=n) then you can write an automation with n actions, each of which adds a new day. Of course, if n = 100, then it’s probably not viable(!)

---

<div class="post-metadata">

**Author:** ![Matt\_Blais](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/matt_blais/32/1464_2.png) [@Matt\_Blais](https://community.fibery.io/u/Matt_Blais)\
**Post date:** [April 30, 2024, 10:50pm UTC](https://community.fibery.io/t/how-to-prevent-infinite-loop-on-rule-triggered-by-formula-field/6137/3 "2024-04-30T22:50:18Z")

</div>

The loop detection heuristic is annoyingly unsophisticated 🙄  
as complained about at length elsewhere.

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [April 30, 2024, 11:31pm UTC](https://community.fibery.io/t/how-to-prevent-infinite-loop-on-rule-triggered-by-formula-field/6137/4 "2024-04-30T23:31:25Z")

</div>

It’s a tradeoff of sensitivity vs specificity - the more lax the logic on what triggers loop detection, the greater the risk of users’ automations causing performance degradation.  
Given that most use cases can be solved with scripting for those inclined/able, it feels like the current balance is OK.  
Having said that, examples like the one above would actually be better solved by directly allowing batch actions in (no-code) automations, rather than tweaking the loop detection to accommodate this particular implementation (requiring helper formulas and a repeating automation).

---

<div class="post-metadata">

**Author:** ![interr0bangr](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/interr0bangr/32/8089_2.png) [@interr0bangr](https://community.fibery.io/u/interr0bangr)\
**Post date:** [May 1, 2024, 1:00pm UTC](https://community.fibery.io/t/how-to-prevent-infinite-loop-on-rule-triggered-by-formula-field/6137/5 "2024-05-01T13:00:52Z")

</div>

> [@Chr1sG](#):
>
> Having said that, examples like the one above would actually be better solved by directly allowing batch actions in (no-code) automations, rather than tweaking the loop detection to accommodate this particular implementation (requiring helper formulas and a repeating automation).

Yeah, adding the ability to loop automation actions without the need for scripts would be very helpful for people like me!

Until that feature someday comes, is there an example of a batch action script you could share that I could try and tweak to work for my current use case?

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [May 1, 2024, 1:10pm UTC](https://community.fibery.io/t/how-to-prevent-infinite-loop-on-rule-triggered-by-formula-field/6137/6 "2024-05-01T13:10:43Z")

</div>

You can either use `createEntity` within a for loop, to generate each of the Days, one at a time, or you can use `createEntityBatch` and send an array of entity objects, one for each Day to be created.  
See here:  
[https://the.fibery.io/@public/User\_Guide/Guide/Scripts-in-Automations-54/anchor=Fibery-service-workspace-functions--86ec1778-15d4-42dc-a533-a57ec38bc855](https://the.fibery.io/@public/User_Guide/Guide/Scripts-in-Automations-54/anchor=Fibery-service-workspace-functions--86ec1778-15d4-42dc-a533-a57ec38bc855)
