Hi guys,
I'm running into this error since a bit now and it is understandable as to why it might be the case but I would like to get some ideas to resolve this or work around this if possible.
Concept :
Field value gets changed/edited through the survey ->
Edited value gets appended into a text field (to keep track of the change) ->
Another field counts how many values are in the text field and reports that.
E.g.:
Existing Value - 2020
Changed Value - 2021
History 2020,
Count 1
Changes again :
Value - 2022
History - 2020, 2021,
Count - 2
I was able to get this working with attribute rules, the js can also do this but since all of these fields are depended on each other to work it is causing a
"Dependency cycles amongst the xpath expressions in relevant/calculate\n\nResult: Invalid"
The values in the first field is pulled from a feature class using pulldata
integer | Last_Preservation | Last Preservation (Pulls Data from a featureclass) |
text | History | History (Keeps track of the changes) |
integer | PRound | Preservation Count (Counts the Changes, String) |
JS - Sample to get a gist of what the process is with Javascript.
// historyUpdater.js
// Function to update the History field with new values
function updateHistory(lastPreservation, currentHistory) {
if (!lastPreservation) return { "updatedHistory": currentHistory || "" };
let historyEntries = currentHistory ? currentHistory.split(", ") : [];
let lastEntry = historyEntries[historyEntries.length - 1];
// Append new entry only if different from the last entry
if (lastPreservation.toString() !== lastEntry) {
return { "updatedHistory": currentHistory ? currentHistory + ", " + lastPreservation : lastPreservation.toString() };
}
// Return original history if no update is needed
return { "updatedHistory": currentHistory };
}
// Function to count the number of entries in the History field
function countHistoryEntries(history) {
if (!history) return { "PRound": 0 };
let historyEntries = history.split(", ");
return { "PRound": historyEntries.length };
}
What would be another way to achieve this result?
Why does the condition says cyclic when the change triggers the rest and it ends, when It does not cycles back.
How it is supposed to work in theory. It does not have to show the other two fields,
For visualization only.
Thank you.
I would make this a repeat and keep the history. You can then use join to display the history easily. I do not think what you have will work out the way that 123 is built.
Thank you,
I experimented with repeat and child table and came across a possible solution for this.
As of now what I have worked around is
The existing value of Last Preservation does not change until the survey is submitted,
So in theory I can still pull that existing data and the field is appended at the end of that pull function to add in the new modified data separated by a , so when it is submitted the values are retained without issues.
This may not require repeats but I just came across this when trying that out. 😄
It has so far let me run and test the same without giving cyclic errors.
if(
pulldata('@layer', 'getValue', 'attributes.Last_Preservation', 'https://arcgis-service-url/FeatureServer/0', concat('Section_ID=', ${Section_ID})) != '' and
pulldata('@layer', 'getValue', 'attributes.Last_Preservation', 'https://arcgis-service-url/FeatureServer/0', concat('Section_ID=', ${Section_ID})) != null,
concat(
pulldata('@layer', 'getValue', 'attributes.Last_Preservation', 'https://arcgis-service-url/FeatureServer/0', concat('Section_ID=', ${Section_ID})),
", ",
${Last_Preservation}
),
${Last_Preservation}
)
There is a little logic around detecting existing empty or null values but that gives the idea. It is still undergoing iterations as new ideas come around.