Select to view content in your preferred language

Prepopulate answers in a repeat with last values

9537
30
08-31-2021 02:40 AM
PaoloBasile_ST
Emerging Contributor

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
30 Replies
lkline
by
Emerging Contributor

Unfortunately no; I've since moved on from the position I was in where I had to work on that form, though!

S_RossWygmans_GISS-T
Occasional Contributor

I was able to resolve this bug by making the select_one a required field. Hope this helps someone!

MelDop
by
Emerging Contributor

Hi Doug,

I've implemented the function you provided in my own survey (thank you). I am more curious than anything-- why is it [position - 2] and not [position - 1]?

 

DougBrowning
MVP Esteemed Contributor

Its been a long time so I forget.  I think it may be 0 based index vs 1 based index.

DougBrowning
MVP Esteemed Contributor

If I remember right it was that 123 was 1 based index and JS is 0 based index.  So they are 1 different than each other. I got this code from someone else on here and modified it so its not really mine.   I am still seeing position() cause loop warnings in Connect.

0 Kudos
S_RossWygmans_GISS-T
Occasional Contributor

@DougBrowning-- I see you've been the OG on this topic for at least the last 7 years! Any fresh developments on the horizon?  It seems like the ability to default to previous iterations in a repeat is a pretty basic function. 

I tried your JavaScript workaround and it worked when the field was set to 'text', but not with the 'select_one' field I’m using. I'm trying to set up a list of foresters for initial user selection, and I want this selection to be carried forward as the default in subsequent iterations. Any ideas?

DougBrowning
MVP Esteemed Contributor

At Dev Summit they did a demo of the new 123 build that will be in .NET now.  One of the things they showed was a repeat as a table with a "Duplicate" option.  That is based on my bugging lol.  I am still not sure if it will be able to handle a repeat with a lot of fields though.  The new build is probably close to a year out still though.

So kind of new info but nothing ready to use today.

I used the javascript on a select one I think.  Are you using the name values and not the label values?  In the end my repeat was too large so it never did work for me.  So not positive.

We used a defaults list in the end which helped a little.

0 Kudos
S_RossWygmans_GISS-T
Occasional Contributor

Thanks @DougBrowning! The squeaky wheel gets the grease (even if it's 8 years later) 🙂

I got the select_one working using the 'autocomplete' appearance -- just doesn't like 'minimal' appearance for some reason.

S_RossWygmans_GISS-T
Occasional Contributor

Oddly enough, I got the select_one minimal appearance to work with the JS just by making a required field 🤔

Neal_t_k
Frequent Contributor

Another not so good option, but I figured I would share.  You can populate the "Hint" with the answer to the previous repeats answer. Screenshot 2025-04-02 165314.pngScreenshot 2025-04-02 165350.pngScreenshot 2025-04-02 165415.png