Populate repeat with external data

482
3
04-30-2022 08:11 AM
LanceCole
MVP Regular Contributor

I have a Survey123 form I am updating to a new version and have a question pertaining to automatically populating a repeat with information from an external source such as a feature service or even an uploaded CSV.  Is this possible?

One section of a monthly inspection form has a list of rain events that exceeded 1/2" and includes the Date & Time, duration, and precipitation amount.  We pull the data from a local Wx station and have the information in a table on our enterprise database.  However, I am currently manually entering this information on each Survey123 inspection and also collecting additional information such as did the contractor perform an inspection within 24 hours, the date the inspection was performed, etc.  It is not bad during the dry seasons, but this spring has been really wet and this month there were 11 events that I am typing on 30+ inspections.

I can easily add an index to the weather data based on the year & month i.e. 202204 that could be used to filter the events to the current inspection month but is there a way to load this into a repeat upon opening a survey?  Is there another option other than a repeat that would allow the information to be loaded and also check off/ complete additional information for each row?

Thanks in advance.

0 Kudos
3 Replies
AlexBakhtin
New Contributor III

Without knowing the overall structure of the from itself, if the weather information you are loading is constant throughout the entire repeat, you can use pulldata() + JavaScript to be able to pull weather information from an API directly into Survey123.

There is a JavaScript sample survey that contains what this workflow could look like in Survey123 Connect:

AlexBakhtin_0-1651525230324.png

Alex Bakhtin
0 Kudos
LanceCole
MVP Regular Contributor

Thanks, the data contains the date, duration, peak intensity, total intensity and amount of rainfall for each rain storm event in a month that exceed 1/2” precipitation.  The data for each event is posted to a repeat row and additional data collected, such as was a inspection report completed within 24 hours, were any issues noted following the event, etc.

I have been experimenting with adding a key to the index in the CSV to each rain event for month such as 202204_01, 202204_02, etc. then using the index of the repeat row from position() and pulldata() to load the data into each of the fields above for each repeat. Still need to figure out how to add 1 to the position() value when using the field app.  Starts at 0 for field app and 1 for web app.

Also, the number of events per month is highly variable, so the number of repeat rows needs to be dynamic as well.  I am using repeat_count in the XLSform and the number of events from another pulldata() to set this value.  However, this section of the form is just really clunky.  I will pull out this section and upload it with a sample CSV file.

I am also looking at generating a JSON rather than using a CSV or embedding the survey in an app and try using the Survey123 extensibility and JavaScript.  In particular the addRepeat Method

 

0 Kudos