When you go to save or upload your form, you may get an error about a cycle being detected, like this:
Error text:
XForm Parse Error: XPath Dependency Cycle:
[details]
Dependency cycles amongst the xpath expressions in relevant/calculate
Alternate error message:
Cycle detected in form’s relevant and calculation logic! The following nodes are likely involved in the loop:
This error is called a "cyclical redundancy" error. It usually occurs when a field's expression (e.g. relevance, constraint, calculation, etc.) is dependent (reliant) either on itself, or it is dependent on a field which itself has an expression that is dependent on the first field, causing an infinite loop. It could also be that a field is dependent on a field that is dependent on another field that is dependent on the first field, and so on. In the end, a field’s expression is dependent on itself either directly or by extension.
For the above errors, the first is more common in field expressions, while the second is more common group expressions.
Understanding the errors
In this section, we illustrate a few examples of fields and groups in forms that have cyclical redundancy errors. Click on the link at the beginning of each paragraph to view the sample form with a cyclical redundancy error.
Example 1, Cyclical redundancy in fields: Take a look at the relevance column (there is an error, so it cannot be uploaded to a server). You’ll notice that the relevance of the select_one field “question1” references “question2”, and vice-versa. The field “question1” cannot continue without “question2”, which cannot continue without “question1”, which cannot continue without “question2”, and so on. The relevance needs to be resolved so that at least one of these fields can work on its own without relying on the other.
Example 2, Cyclical redundancy in groups: The issue here is very similar, but instead, the relevance of “grp_a” is based on a field within “grp_b”, and in turn, the relevance of “grp_b” is based on a field within “grp_a”, so they are dependent on each other by extension, causing an error.
Example 3, Cyclical redundancy in complex groups: While the above examples are more direct, they can get infinitely complex. In this sample, the group “grp_a” has a relevance based on “question_b1” within “grp_b”, and the relevance of “grp_b” is based on “question_c2”, which itself has a relevance based on “question_a1” inside “grp_a”, which has a relevance based on “question_b1”, and so on. Even though the relevance relationship is not as direct, it is still there, and causes an error that needs to be resolved before it can be properly used.
Resolution
Even with basic forms, this can be a tough error to troubleshoot. It can take time to track the cycle and find where the issue is, especially in longer forms. Track down the cycle, and remove a field reference that is part of the cycle so it is no longer a cycle.
1. Find a field that is part of the cyclical error
This may be listed in the error message. For example, if you upload example 1 to your server, the error message says the cycle involves the fields "question1" and "question2".
Error uploading form: The form definition could not be processed:
XForm Parse Error: XPath Dependency Cycle:
/cyclical_redundancy/question2 => /cyclical_redundancy/question1
/cyclical_redundancy/question1 => /cyclical_redundancy/question2
Dependency cycles amongst the xpath expressions in relevant/calculate
2. Check the expressions
Once you find a field that is part of the error, check all of its expressions, including its relevance expression, its calculation, and others, and note all field references it uses (field references will be in dollar-sign-curly-brackets like ${this}
).
3. Follow the cycle
Take a look at the fields referenced in step 2. Just like in step 2, in those fields, check the field references used in the expressions. If there are too many field references to look for, try to find a different field involved in the cycle that uses fewer field references.
Keep working backwards like this until you find the field reference to the first field you found that is part of the cycle. You have now found the cycle.
4. Break the cycle
Edit the expression of one of those fields that is part of the cycle so there is no longer a cycle (i.e. edit the expression so you can no longer trace field references back to the starting field like you just did). Once there is no longer a cycle, this error will be resolved.
Tips for finding and breaking the cycle
If you are having trouble following and breaking the cycle, check out these tips to help you along.
Slowly delete fields
If you are having trouble finding the cycle, make a copy of your form, and then in that copy, slowly start deleting fields, then uploading the form to the server. When you are able to upload the form to the server without getting the cycle error, it means you have deleted a field that is part of the cycle, and you can use that to help determine which field reference needs to be removed so you can break the cycle.
Because you are deleting fields, you may get errors saying that certain fields do not exist. You will also have to delete the references to the fields you are removing in order to avoid this error.
Use calculate_here
Sometimes, changing a calculate field to a calculate_here type field can break the cycle. This is because calculate_here fields only update when you reach them in the field, so they are not constantly updating, so they cannot cause an infinite loop. For example, check out this sample form: the field "another_here" is a calculate_here field so there is no cycle, and the field "last_another" is a calculate_here field so that it updates when needed.
However, avoid using calculate_here fields whenever possible and use calculate fields instead . Not only do they use more processing power and device resources, but since they only update when you get to them in the form, they will not update automatically when any of their parts are changed. For example, you were to go back and change a field that is used by a calculate_here field, the calculate_here field would not update again until you pass by it again. It is better to use normal calculate fields when possible, and break the cycle itself. However, there are exceptional circumstances where a calculate_here field is the right choice.
Do you have thoughts on this support article? We'd love to hear them! Feel free to fill out this feedback form.
0 Comments