Copy a Repeat Answer to the next Repeat in Survey123 Connect

1227
7
Jump to solution
03-06-2020 08:08 AM
Alena
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!

0 Kudos
1 Solution

Accepted Solutions
DougBrowning
MVP Notable 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.

https://community.esri.com/thread/241309-populate-a-field-within-a-repeat-from-a-previous-entry-with... 

Hope that helps

View solution in original post

7 Replies
DougBrowning
MVP Notable 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.

https://community.esri.com/thread/241309-populate-a-field-within-a-repeat-from-a-previous-entry-with... 

Hope that helps

Alena
by
New Contributor III

Thank you Doug Browning! That worked!

0 Kudos
MikeWright
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?

DanielWebb
Occasional Contributor

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

0 Kudos
MikeWright
New Contributor III

Unfortunately no.

0 Kudos
AndyMcClary
New Contributor III

@DanielWebb and @MikeWright 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.  

0 Kudos
BrandonA_CDPH
Occasional Contributor

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  

0 Kudos