Prepopulate answers in a repeat with last values

1439
14
08-31-2021 02:40 AM
PaoloBasile_ST
New Contributor II

Hello everyone,
I can't seem to create a Survey where the repeat values are prepopulated with the same values as the last record inserted in the repeat (I'm also using the Inbox option).

Let me explain:
I have a form with a geopoint and a repeat that contains two values: date and note

Geopoint
Repeat
-date
-note
end repeat

Image1.JPG

The surveyor has to find the nearest point to him (use Inbox) and has to insert a new repeat record with the date calculated automatically (I know how to do it) and a new note whose value must not be empty but must be prepopulated by the value of the previous note (I don't know how to do it).

I tried using the indexed-repeat () function but I get a cyclic error.

Image2.JPG

Do you have any suggestions?

Thank you in advance for your attention,

 

Paolo

 

0 Kudos
14 Replies
DougBrowning
MVP Honored Contributor

Oh now I see it you changed the name of the variable at the top of the function but then kept using the word repeat in the code.  May want to read up on how functions work.

Change the code back to use repeat.  You did that with fieldname also.  You change what to send to the function in the pulldata you do not change the names used inside the function.

Change back to my code in the .js file  See how the name repeat is in the first line then used in the function?  See how fieldname is in line 1 then used in the function.  You changed line 1 but not the other code.

 

 

function sameaslast(repeat, position, fieldname) {
	if (position > 1){
		return repeat[position - 2][fieldname];

	}
}

 

 

Hope that makes more sense now.

0 Kudos
LeahSperduto1
New Contributor II

So that definitely helped. After publishing, however, it doesn't work when using it in the applications.

Is it intended to work in both the native app (using new collection and/or inbox) and also as a web app survey?

When demo'ing in Connect, I get the Site_Addr field to repeat the original entry as desired/expected.

Upon publishing:

In the native app I still get the error in the Site_Addr field.

In the web app I get nothing in the Site_Addr field.

 

Thank you so much!

0 Kudos
DougBrowning
MVP Honored Contributor

Make sure you have the latest version of the app.  Note JS cannot be used in public surveys or across Orgs.

The app error seems like it maybe the form is out of date.  Maybe delete and redownload.

Looks like the web app may need some config stuff https://community.esri.com/t5/arcgis-survey123-blog/introducing-the-survey123-web-app-javascript-api...

Not sure I never use the web as my forms are too complicated.

0 Kudos
RossCampbell3
New Contributor II

Thanks for sharing this Doug!

The only issue I was having using this script is it was overwriting manual entries (with the value from the previous repeat) when users were scrolling back through the repeats to review their entries.

To get around this, I put the pulldata in a once() function. Seems to be working smoothly now.

Thanks again!

Ross

AndrewThompson_SCE
New Contributor

Hi Ross,

I am looking into doing this as well. I have most of it from reading this thread, but something is still off. Could you post your completed code here? 

Thanks,

 

Andrew

0 Kudos