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
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.
Do you have any suggestions?
Thank you in advance for your attention,
Paolo
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.
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!
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.
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
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
Thanks for sharing this solution @DougBrowning ! In my particular situation I needed to calculate the same field for every repeat record in such a way that each value would be unique. Your JS function allows me to look up the previous values without getting stuck in a dependency cycle.
I'm currently using your code as is to get the previous value for every repeat record and then I'm merging these with the XLSForm join function in another field outside of the repeat. Although this works fine, I imagine your function could be adjusted so it does both of these separate actions in one JS function. I haven't had the time to test this yet but calling slice (0, (position-2)) on the fieldname array and then using a join in JS might return the desired result in this case.
Hello! I've gotten this function working for text and integer type questions (it's been a lifesaver), but encounter a glitch when I try to use it on select_one questions. Here is a screenshot of my xlsx setup:
Row 36 shows the select_one type question. Although the integer and text questions work correctly (rows 33 and 34), this is what I see when I attempt to select a transponder:
You can see that, after clicking several times, the drop-down will appear very quickly, then disappear. Has anyone else encountered this, or am I trying to use the function incorrectly here? Thank you!
I am also experiencing this issue! Doug posted it here:
Using a JavaScript pulldata in a calculate breaks ... - Esri Community
I have been trying dozens of ways to get a same as last type button like our old app had for 6 years now and have still not found anything that works. I even have been bugging the team on it but still no solution. So sorry I have no answers for you.
Overall our main complaint from users has been that it is really slow and clunky to collect data in 123. And I agree it is 123s biggest downfall and it just does not seem to have importance in the development. As we seen often in Esri apps is they tend to focus on new shiny things instead of really dialing in the core functions. I hope the next gen really concentrates on data entry speed and true smart forms that can predict the next answer. For example another idea is to have the tablet SQL Lite db track number of times a drop down list item is chosen and sorts by frequency. Would be pretty easy to implement.
Testing out in the field or adding team members that have in the field experience would really help I think.