Select to view content in your preferred language

Populate Repeat Count set with previous Repeat Count set data

1052
7
06-20-2021 03:56 PM
MSmith1
New Contributor

Hi there.

I am creating a survey with a repeat_count of 60 observations. It is likely that many of the adjacent repeat observations within the set of 60 will have the same data, i.e. the observation for repeat 12 (out of a set of 60) will be the same as for repeats 10 and 11 etc. Is it possible to pre-populate data for a repeat with the data from the previous repeat, but still retain all data selection options? i.e. data for repeat 11 is automatically populated with data from repeat 10, but the user can change the data for repeat 11 if required, then, data for repeat 12 is automatically populated with data from repeat 11, also editable if required.

Thankyou

0 Kudos
7 Replies
codergrl
Occasional Contributor

@MSmith1 I would recommend using JavaScript to achieve that. Take a look at this resource: Passing a repeat to pulldata("@javascript")

0 Kudos
DougBrowning
MVP Esteemed Contributor

I have been trying to get this for a few years now but no go.  We had an old program that had a "same as last" button.  Been asking the 123 for it a number of times but The issue is that the formula would need to be something like FieldA = FieldA which of course makes no sense.  There is no way to say give me repeat answer 12.  I have seen syntax in errors like repeatname/1/fieldA but I see no way to use this in a calc.

See the link in this recent post for some ideas.  https://community.esri.com/t5/arcgis-survey123-questions/calculate-create-default-repeats-or-favouri...

Never tried with javascript since we work across org accounts and thus it is blocked.

Hope that helps.

0 Kudos
codergrl
Occasional Contributor

@MSmith1 Threw something together to test this, seems to do what you're needing. Good luck! 

function myfunction(testrepeat, position) {
	if (position > 1){
		return testrepeat[position - 2].text1;
	}
}

Capture.PNG

 

 

0 Kudos
DougBrowning
MVP Esteemed Contributor

Thanks for this @codergrl .  How can I have it pass in the field I want so that the function is more generic.  I am not getting it.

function sameaslast(repeat, position, fieldname) {

if (position > 1){

return repeat[position - 2].fieldname;

}

}

pulldata("@javascript", "functions.js", "sameaslast", ${LPIDetail}, number(${RecCount}), "TopCanopy")

If I hard code it works  return repeat[position - 2].TopCanopy;

this does not work  return repeat[position - 2].[fieldname];

thanks

0 Kudos
DougBrowning
MVP Esteemed Contributor

Opps forgot to take the dot out.  It now works.

function sameaslast(repeat, position, fieldname) {

if (position > 1){

return repeat[position - 2][fieldname];

 

}

}

0 Kudos
codergrl
Occasional Contributor

Try this:

return eval("testrepeat[position - 2]." + fieldname);
0 Kudos
DougBrowning
MVP Esteemed Contributor

Thanks I jus forgot to take out the dot.   return repeat[position - 2][fieldname]; works fine.

But now I found that if I use this function more than twice in my form it crashes iPads.  Android and Connect work fine only iPads.  If I use it one or twice no problem, a 3rd time on any field and it crashes.

Weird

0 Kudos