Populate a field within a repeat from a previous entry within same repeat?

1120
4
Jump to solution
10-07-2019 08:00 AM
MattCobb
New Contributor II

I'm working on a vehicle usage log for Survey123 that our field crews can track mileage for their vehicles.  Within a repeat group, I have fields of Starting Odometer and Ending Odometer.  Is it possible to auto-populate the Starting Odometer field based on the previous Ending Odometer record within the repeat?

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DougBrowning
MVP Notable Contributor

I do this. 

Create a field outside the repeat with a max on it and you will get the last value since you know it is the largest

max(${GapEnd})

Then in your repeat grab the max using once so that it does not change on you if they go backwards to view or edit.

once(${maxGapEnd})

View solution in original post

4 Replies
DougBrowning
MVP Notable Contributor

I do this. 

Create a field outside the repeat with a max on it and you will get the last value since you know it is the largest

max(${GapEnd})

Then in your repeat grab the max using once so that it does not change on you if they go backwards to view or edit.

once(${maxGapEnd})

MattCobb
New Contributor II

Doug Browning‌ this is brilliant, worked perfectly.  Thanks a ton!

0 Kudos
FRSadmin
New Contributor III

Hello, I don`t know if you will see this so many years later.

I am pretty novice at coding and I am trying to do something similar but am missing steps in between.

I want to be able to have a pulldown list to select the vehicle, and then for each vehicle have each odometer information stored.

I guess my questions are

A) under the survey tab how do I link the data from my chosen vehicle to the starting Odometer 

B) I am unsure if all of your code is direclty in the script portion? and how can I use the script under the survey tab...

0 Kudos
FRSadmin
New Contributor III

Hello,

I responded to this just a few minutes ago but I am wondering if you could tell me? maybe show me how you were able to solve this.

I am not planning on having a repeat function, but rather I have a pulldown list of vehicles and then based on what vehicle you selected I want to be able to readin the Starting Odometer automatically.

Does this require a single script and then an individual excel spreadsheet for every vehicle?

For example if I have a Corolla selected, I need to have  a matching excel spreadsheet Corolla.xl that then has a start and end column? Or just a single column that then tracks different values?

A screenshot or anything you have would help wonders as  I also do not know Java...

0 Kudos