# Copy a Repeat Answer to the next Repeat in Survey123 Connect

2767
7
Jump to solution
03-06-2020 08:08 AM
by
New Contributor III

There is a top depth and a bottom depth in a repeat...Is it possible to copy automatically a bottom depth to a top depth in the next repeat?

Thanks!

Tags (2)
1 Solution

Accepted Solutions
MVP Esteemed Contributor

You cannot really copy but if you know the fields are in order you can pull it off.

See this post  I go it with Gap and with Soil Dept.  I thought there were more posts but I can't find them.

Hope that helps

7 Replies
MVP Esteemed Contributor

You cannot really copy but if you know the fields are in order you can pull it off.

See this post  I go it with Gap and with Soil Dept.  I thought there were more posts but I can't find them.

Hope that helps

by
New Contributor III

Thank you Doug Browning! That worked!

New Contributor III

I'm trying to solve a similar problem, except I am looking to "carry forward" the value from 'Question 1' into the next repeat 'Question 1'. Any attempts at referencing Question 1 in a calculation for Question 1 result in a Dependency Cycle error - even if the value from the previous Question 1 is stored in a temporary field, and that field is referenced in the calculation. Any insights on a possible work around?

Occasional Contributor

@Vince_ERAC  This sounds like what I'm trying to do.  Did you ever get this to work?

New Contributor III

Unfortunately no.

New Contributor III

@DanielWebb and @Vince_ERAC The way I've been able to make this work is by using a simple JavaScript function. The key there is that you can pass the whole repeat to the function and then return the field value you want so you avoid the dependency cycle error. Here's the function:

function previousvalue (repeat, recordnumber, fieldname)

{

if (recordnumber > 1) {

return repeat[recordnumber-2][fieldname];

}

}

And here's an example of the pulldata calculation you would do in a field outside the repeat:

pulldata("@javascript", "functions.js", "previousvalue", \${occupants}, \${current_record}, "occupant_name")

where occupants is the name of the repeat, current_record is a field outside of the repeat that stores the index of  the repeat record you are currently on, and occupant_name is the name of the field inside the repeat that you want to carry the value forward for. I attached a demo .xls to help show how to set this up. This used to be slow with big repeats but with the 3.14 update I haven't encountered any issues.

Occasional Contributor II

This may be a place for a calculate and field outside the repeat - something like TopDepth outside repeat - inside repeat the TopDepthRepeated question has \${TopDepth} in the calculate column. Could even make  the repeated field read only or hidden. This has worked for me in similar situations