Infinite Loop
When designing your workflow it is possible to add workflow steps in such a way that it causes an infinite loop at runtime.
In most cases these infinite loops occur due to incorrect design, where steps loop back on to themselves without going through an asynchronous step (like a Task step, or a SmartObject step in which you've enabled the "Wait for an external system" option). In other cases, a step may trigger an external event that the workflow listens for to start new workflow instances and thus causes an infinite recursive loop of workflow instances. You can resolve infinite loop warnings by moving the steps around or by adding different paths for the workflow to follow.
In some cases, however, your workflow design might warn you about an infinite loop but the loop logic that you've configured is completely valid. In these cases, you can safely ignore the warning and deploy your workflow.
An infinite loop can cause the server to become unresponsive. Because of this, when an infinite loop is detected in your workflow design, you will see a yellow warning badge on the step and a corresponding warning message in the error console. Additionally, you will see a general warning beneath the deployment button. Warning badges never prevent you from deploying your workflow.
Here are some points to consider when you see this warning:
- Determine if a Task step should be inserted between two steps that loop, such as a Rework task for the Originator
- Insert a SmartObject step that waits for an external event. For more context see Example 2
- Reconfigure your workflow so that it doesn't need to loop but rather flows into an End step or back to a Task step instead
- If you decide that your workflow logic is sound, it is recommended that you run a few test scenarios to make sure your workflow instances complete as expected and do not infinitely loop
Use the following examples for determining if you need to redesign your workflow or you can safely ignore the infinite loop warning.
In this example you build your workflow and, while connecting workflow steps together, you notice an infinite loop warning badge on one of the steps (the Create List Item step). Click the yellow error indicator located at the bottom right of the canvas. The error indicator shows the number of warnings and errors.
The error console opens.
You find a description of the warning and the step on which the warning or error occurs. In this example, the Create List Item step loops back on itself in a way that could cause an infinite loop.
Verify that your design is correct. If not you need to make changes to the arrangement of workflow steps because an infinite loop can cause performance degradation on the server. In this example remove the path from the Placeholder step to the Create List Item step.
You can still deploy your workflow although the infinite loop warning message shows. In this example, looping back to the Create List Item step will cause many more items to be created in the list that is expected as there is no logic to exit the loop. It is best practice for all loops to have an exit condition.
As part of a loan application, your company checks the applicant's credit score with the credit bureau. In your workflow you add a SmartObject that connects to a credit bureau to request a credit score. This step could be part of a loop if there is the ability to have the user provide more or different information and resubmit at a later time. This process could take several minutes to complete and rather than hold the connection open, the SmartObject makes the initial request and then the credit score system calls back in to the workflow to complete the asynchronous step once the score is available.
Notice the infinite loop warning badge on the Credit Score SmartObject step. Click the yellow error indicator located at the bottom right of the canvas.
The error console opens.
In here you find a description of the warning and on which step the warning or error occurs. In this example, the Credit Score SmartObject step loops back on itself in a way that could cause an infinite loop.
To make sure the workflow to completes the asynchronous step, check the Wait for external system check box in the Option section. This means the workflow waits until the external event completes.
As part of your company marketing strategy an email is sent to your customer base every 30 days. The marketing department signs off on the email template once a year. Data from an external system is used to fill customer-related details in the email using a SmartObject. The workflow starts and Codi, the head of Marketing, receives a task to approve or reject the template. Codi approves the template and the email is sent to the company customer base. A Timer step makes sure that after 30 days the workflow path continues back to the Send Email and sends out another email to all customers. This process continues indefinitely.
In this example, you can safely ignore the infinite loop warning as your logic in the workflow is valid.
In this example the workflow starts when an item is added to the Employee Details SharePoint list. When you add the Create List Item step in the workflow, the infinite loop warning badge shows on the step. In this case it's not one workflow instance that loops but rather a recursive loop of workflow instances started in an uncontrolled way which will cause performance degradation on the server.
You can still deploy the workflow, however it is recommended that you remove the Create List Item step and rethink your workflow design.