Reputation: 497
I have a workflow that updates a custom field on the Quote entity when the Quote Total amount is updated. When the workflow is executed the below error occurs.
“This workflow job was canceled because the workflow that started it included an infinite loop. Correct the workflow logic and try again. For information about workflow logic, see Help.”
To reproduce this error, create an on demand work flow that has an update step. The update step sets the quotes deposit to 100. Execute the Workflow, then navigate to the Process Sessions area of the workflow. You will see the work flow has been executed numerous times. If you open a process session record you will see the error mentioned above.
I assume this occurs because when the quote is updated the total amount is re calculated, when the total amount is re calculated then workflow is executed, when the work flow is execute the quote is update and when the quote is update the total amount is update and so on and so on and son.
For Example
Quote Is Update
Total Amount is re calculated
I hope this makes sense
Does anyone know or have any ideas on how to solve this?
Upvotes: 1
Views: 325
Reputation: 11
You dont update Total amount, you update a custom field. Are you sure the workflow doesn't trigger also on that custom field change?
Upvotes: 0
Reputation: 1761
Change your workflow code to not update the Quote if it is not actually making any changes. I assume that the Total Amount is getting set to the same thing over and over, and that is why you're getting an infinite loop, as that is a trigger for the workflow again.
If you do not update the Quote if it does not need to be updated, you obviously won't trigger another workflow.
See this example to see how to check the previous values of the record in the workflow activity code.
Upvotes: 0
Reputation: 132
At the start of the plugin:
if (Context.Depth > 1)
{
return;
}
It will exit the plugin if triggered by another plugin, therefor exiting out of the loop on the second trigger. It is what I use when I register a plugin on update so that it doesn't start all over again.
Hope it helps.
Upvotes: 2
Reputation: 3107
Find an unused field (or create a custom one if there is none), and use it as a flag.
Set it to some value in your workflow, and before doing any update on the Quote record, check this field's value to determine if the workflow has already updated the record.
If the workflow has already been run once, stop the workflow without doing any updates on the Quote record, so you can prevent the infinite loop.
Upvotes: 0