Have a repeat in survey123 default to last record entered

922
10
01-21-2021 08:28 AM
TomBaldvins
New Contributor

Hello,

I am creating a form in survey123 that records plant species along different transects. It would speed up productivity a lot if the survey could default to the last species selected. Has anyone set up a survey like this before? I am trying to capture the last species collect in a text field outside the repeat, but I am getting the error below. I am attaching the survey below. 

Thank you!

TomBaldvins_0-1611246410876.png

 

Tags (2)
10 Replies
DougBrowning
MVP Notable Contributor

Are you trying to do something like a Same as last button?  If so then no can't do it if the size of the value varies.  I created a page with a default values setup then it asks you Use Defaults?  Best I could do.  I posted on this but cannot find it in the new system.

I have been asking for the lists to auto sort based on the last choice for some time now.  A lot of this was talks with the 123 team or in the early adopter so I cannot link to them but this is one from 2018  https://community.esri.com/t5/arcgis-survey123-questions/how-to-random-sort-choices-in-a-question/td....

I see you say LPI in there.  I have a LPI form already as part of our program for a Fed agency.  Are you Fed by chance or work with one?  If so DM me and I can get you more info.

Also move your list to external choices and it will be much faster.

 

Edit just seeing some of this is coming in the new beta.  I will be testing this soon.

Hope that helps

0 Kudos
TomBaldvins
New Contributor

Hello Doug,

Thank you for your response. I am currently working for a Natural Heritage Program, and work with several federal agencies. This LPI form is based on one we developed for some BLM aim studies. We are now trying to adapt it for forestry surveys.

Thanks,

Tom

0 Kudos
emilperlt_rrc
New Contributor II

Hey Doug,

Any advice on setting this up if the size of the value doesn't vary?

I tried using indexed-repeat(${same_field},${same_repeat},position(..)-1) and the same thing referencing a 'count(${repeat})-1' calc field outside the repeat instead of position(..). No luck in either case, unfortunately.

Thanks,

Emil

0 Kudos
DougBrowning
MVP Notable Contributor

Not sure what you mean about size does not vary?

indexed repeat will not work when trying to bring it into the next repeat to a field with the same name.  It can only show it in a different field.  This more or less makes the function useless for most uses.

The only way I have ever got same as last to go into the same field is using javascript - but my repeat is too big (at 60 fields) and blows up with a memory issue.

Is that what you meant?

emilperlt_rrc
New Contributor II

That's exactly what I meant. Thank you for the clarification!

My repeat is rather long too so I'll avoid javascript for the same reason. I'll just go with a default value page for now as you suggested above.

0 Kudos
LarryWiebe
Occasional Contributor

Hi Doug,

I have a small repeat that I am trying to do this with, would you be able to share the javascript for pulling the value for the same attribute name from the previous position in the repeat?

Thanks,

Larry

0 Kudos
DougBrowning
MVP Notable Contributor

It is actually working in the new 3.14 with the new fast calc engine.

 

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

actaul function

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

	}
}

 

 

Note take the comments out

Oh Also note you can use position({repeatname}) instead of reccount now!

DavidHines
New Contributor II

Hello Doug,

Can this code be modified to not use with repeats?  I want the previous value for field in the main survey instead of a repeat.

Also how do you make a default value page?  Just add another page that has defaults values for each question?

I work for the US Fish and Wildlife service, I am creating a survey to record daily fish feeding at a National Fish Hatchery.  The feed type and size only changes every 1 or 2 weeks,  they don't want to enter the type and size for each pond but they will need to change it when appropriate.  If I can get the survey to repeat the last value entered for those two questions, this should solve the problem.

Thank you.

0 Kudos
DougBrowning
MVP Notable Contributor

So you want to lookup into older forms?  That can be done with pulldata to the service but you would have to be online.  

Offline you could just open the last form and make a copy, or you could launch from Field Maps and it send the last values to 123 via URL.  Field Maps could have the value in a field from script each night or use Arcade and FeatureSet to lookup and get the last value.  Or based on what you posted you may want to make set values in Field Maps so it tells them what value to feed.

I guess I need more info.

For the defaults page its simple - just a if to use or do not use.

if(${UseDefaults}='Yes',${CollectionNumberTopDefault},'')

LPI Defaults.gif

 Hope that helps.  

0 Kudos