Use previous value within a repeat group

commcare

Do you have a workaround on how to use a previous value of a variable within a repeat group in another variable in the repeat group without having a circular reference error? For example my user is supposed to enter a number of foods with different time of consumption but we also want to have the option to select type = same as previous. But when I'm trying to use the time[x] = time[x-1] where x is the current position I have circular reference error.

Best Answer

I would need a bit more information about your configuration to properly design a solution, but I would suggest examining the following document on repeat groups. In particular, I would examine the sections on the .., current() and position() functions. These are three functions used specifically for repeat groups that allow you to reference specific nodes that have been created by a repeat group. Based on your description, you could potentially use a combination of the current() function and the position() function to bypass this circular reference error. I hope this helps!