Select to view content in your preferred language

Copy a Repeat Answer to the next Repeat in Survey123 Connect

3454
7
Jump to solution
03-06-2020 08:08 AM
Alena
by
Regular Contributor

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 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.

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 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.

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

Hope that helps

Alena
by
Regular Contributor

Thank you Doug Browning! That worked!

0 Kudos
Vince_ERAC
Regular Contributor

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
Frequent Contributor

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

0 Kudos
Vince_ERAC
Regular Contributor

Unfortunately no.

0 Kudos
AndyMcClary
Regular Contributor

@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.  

0 Kudos
BrandonA_CDPH
Frequent 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