Update Choice list with Python API in Notebook

2544
9
03-30-2021 02:01 PM
KerryKang
Occasional Contributor II

Hello all, 

I have a survey that requires frequent update on the choice list. Since the survey content may need to be managed by actual users who are not familiar with Survey123 connector at all, I hope to find a way to do it using Python API. 

My idea is that the Python script is stored in Notebook on ArcGIS Online so it can be managed on cloud environment easily and people with the permission can access. Has anyone used Python API to do this?

 

Thank you.

 

Kerry

0 Kudos
9 Replies
ZacharySutherby
Esri Regular Contributor

Hello @KerryKang

If your survey uses select_x_from_file and your choices are stored in a CSV file in the media folder we have a notebook (we are working on documentation for the workflow) that can be used to update that CSV in the media folder. 

If your choices are in the choices worksheet in the survey that is a bit more difficult as there are a number of steps that would need to be taken. We are working on supporting this workflow in the Survey123 module of the python API. 

At the moment the workflow that I would recommend would be to host a CSV for the choices in your ArcGIS Online content, use select_x_from_file in your survey, link the CSV from your Org content to the survey (please refer to this documentation: https://doc.arcgis.com/en/survey123/desktop/create-surveys/xlsformessentials.htm#ESRI_SECTION1_34A4D...), and then a script using the ArcGIS API for Python can be used to update the Org item CSV which will then auto update in the survey. 

I've attached a simple script that I've been using for testing the linked CSV workflow that uses the Python API. 

Thank you, 

Zach

Thank you,
Zach
KerryKang
Occasional Contributor II

Hi @ZacharySutherby  thank you for providing the alternative solution. I have not user the external choice but it sounds actually very efficient. I will take a look at the url and the sample script. 

Cheers, 

Kerry

0 Kudos
KerryKang
Occasional Contributor II

Hello @ZacharySutherby 

 

I used the external choice list method as advised but it looks like the selection list is not updated properly. To test, I overwrite the csv manually and also used Python API. This is what I did.

 

1. Survey has been published.

2. Created a csv file for external choice and uploaded on AGOL.

3. Downloaded csv within Linked Content and republished the survey. --> I can see the new list from csv.

-------

4. Overwrite csv manually with new file from the hosted table published.

5. Checked the survey. The selection list has not been changed.

-------

6. Updated some values (name/ label) in the csv table from Data page on AGOL directly.

7. Checked the survey. The selection list has not been changed.

-------

8. Overwrite csv automatically using the sample Python script.

9. Checked the survey. The selection list has not been changed.

-------

10. Republished the survey. The selection list has not been changed

-------

11. Downloaded csv in Linked Content (updated from previous steps) and republished the survey. Then the list has been updated.

 

Based on my observation, I need to open Survey123 Connect and download csv within Linked Content?  I am not sure if I am missing any step. What I ideally like to see is that the list can be updated by end users who does not have the survey123 connect installed. There will be multiple of this survey and I won't be able to support in updating list in a timely manner.

 

Cheers,

 

Kerry

0 Kudos
ZacharySutherby
Esri Regular Contributor

Hello @KerryKang

You don't need to do step 3 in the workflow above. I would actually advise against doing step 3, just as Lee was seeing in the other Esri Community post what was happening was the update media folder script was working with a separate CSV than the linked one and when the script extracted the ArcGIS Online Form Items media folder it added the current timestamp the script was running to the file modify time.

Since there was an older version of the linked CSV in the ArcGIS Online Form Items media folder the field app thought it was working with the most recent version due to the time stamp, although it was using an older version.

 

If you removed the linked CSV from the media folder and republish the survey do you see the same behavior? 

Thank you, 

Zach

Thank you,
Zach
0 Kudos
KerryKang
Occasional Contributor II

Hi @ZacharySutherby 

I reposted the question last week and I was advised to try with v3.12 mobile apps. It works fine  while I have the csv downloaded in the media folder (even if it's not the latest one). But once I remove the csv from the media folder, I don't see new list from the update csv. This is what I tried today.

 

1. Removed csv in the media folder.

2. Updated CSV on AGOL (let's say A.csv)

3. Refreshed Survey123 mobile app, there is no notification on csv update.

4. Re-published Survey123 through Suvey123 Connect.

5. Refreshed Survey123 mobile app, there is no notification on csv update.

6. Downloaded A.csv linked content .

7. Refreshed Survey123 mobile app, it asks to update. I could see the list from A.csv.

8. Updated A.csv to B.csv on AGOL

9. Refreshed Survey123 mobile app, there is a notification on csv update. I could see the list from B.csv.

 

As mentioned, I hope to get this work with web forms. However it looks like I need to go through download linked in content and republish all the time to apply updated list in web form. I saw that there is a new solution coming in May that uses feature tables to generate dynamic list. Would it work for web forms, too?

 

Cheers,

 

Kerry

0 Kudos
HaochangLi
New Contributor II

Hi, 

I am trying to test this linked CSV method, however, once you update the AGOL hosted CSV, the list value won't update in your existing survey. To make it work for me, I have to completely delete the current survey and re-download it on my mobile device.  Is this a bug or it just me?  

0 Kudos
KerryKang
Occasional Contributor II

What version of mobile app are you using?? When I tried this with 3.12 version on the mobile app it worked fine. There will be a notification window saying that csv has been updated and will redownload it automatically after the csv on agol is updated. I need to use it on the web browser though and haven’t figure it out how I can make it work. 

kerry

0 Kudos
HaochangLi
New Contributor II

The mobile apps i am using is 3.12.277, i just downloaded it yesterday.  i did saw the re-download/refreshing CSV once the update pushed in AGOL. however, the list still with the old one. After i delete the survey and re-download it, the update is there. 

0 Kudos
JHONATHANCARDENASRODRIGUEZ
New Contributor

Hola, he intentado varias opciones de cargar archivos externos, pero no me da la actualización del listado de más 1000 datos. No logro entender, como hacerlo 

0 Kudos