Hi Glide Community!
First off, I just want to say how much I appreciate this community. You all provide so much value, and I’m hoping someone can help me troubleshoot a problem I’m having with loops.
What I’m Trying to Do:
I’m building a lead distribution workflow that:
-
Reads an Excel file attached via email, converts it to JSON, and loops through each lead to assign it to an agent.
-
Agents have a predefined distribution percentage.
-
Leads are assigned randomly, but the assignment respects the agents’ distribution percentages using cumulative math (e.g., Random Number < Cumulative Percentage).
-
Each lead should only be assigned to one agent, and the loop should stop for that lead once it’s assigned.
The Current Workflow:
• Loop All Leads: Loops through all the leads extracted from the email file.
• Within Loop All Leads:
• Sets cumulative values for agents based on their distribution percentage.
• Loops through the agents to find one where Random < Cumulative.
• Assigns the lead to the agent if the condition is met.
The Problem:
• The agent loop (Loop Through Agents) keeps iterating even after the lead is assigned to an agent.
• It results in multiple leads being assigned incorrectly or more iterations than expected (e.g., 28 iterations for 4 leads and 7 agents).
• I tried using conditions like “if the Email field is not empty, skip,” but I can’t seem to apply this logic effectively within the workflow.
What I’ve Checked:
• Cumulative math appears to work as expected (logs show it hitting 100).
• The issue seems tied to how the workflow handles exiting or skipping when a lead is already assigned.
Screenshots:
- Workflow Setup:
- Logs:
• Shows how cumulative math is calculated correctly.
• Also shows the excess iterations in the agent loop.
I’d really appreciate guidance on:
• How to exit a loop or skip iterations after a condition is met (e.g., lead is already assigned).
• If there’s a better way to structure this workflow logic to avoid unnecessary iterations or start in a new direction for a round-robin type of lead distribution based on pre-defined %?
Thank you so much in advance for your time and expertise! If you need more details, I’m happy to provide them.