Select to view content in your preferred language

Updating a CSV file in media survey123 form

902
2
08-03-2022 05:03 PM
neomapper
Occasional Contributor

I'm stuck. I am trying to overwrite an existing csv file on a survey I published but it's not working. I have no errors. I run the script but the csv file doesn't change on the media folder on AGOL when I redownload the published form in survey123 connect. What am I doing wrong?

import arcgis
from arcgis.gis import GIS
import tempfile
import zipfile
import shutil
import os

# Script Parameteres
portalURL = r'https://egas.maps.arcgis.com/'
username = '***'
password = '***'
itemID = '***'
updated_files = ['Join_Features_to_Monitoring_Routes_v411_0.csv']
source_loc = r'C:/Users/jnmiller/Downloads/'
download_folder = r'C:/Users/jnmiller/Downloads/'

#----------------------------------------------------------
# Connect to GIS
gis = GIS(portalURL, username, password, verify_cert=False)
#------------------------------------------------
survey_manager = arcgis.apps.survey123.SurveyManager(gis)
surveyId = survey_manager.get(itemID)
surveyProp = surveyId.properties
print(surveyProp)

 

0 Kudos
2 Replies
DougBrowning
MVP Esteemed Contributor

I would check out the newish linked content.  You add a CSV to AGOL then link to that.  I think that would be easier to update via script.  I update manually but it has been way easier.  I have 12 forms all linked to one central people list.

See

https://community.esri.com/t5/arcgis-survey123-questions/can-a-linked-csv-file-on-agol-be-automatica...

https://community.esri.com/t5/arcgis-survey123-blog/work-with-csv-data-in-arcgis-survey123/ba-p/1157...

https://doc.arcgis.com/en/survey123/desktop/create-surveys/xlsformformulas.htm#:~:text=In%20Survey12...

Hope that helps

0 Kudos
AndyMcClary
New Contributor III

Is that the full script? There's nothing in that script to actually update the csv, you're just getting the properties of the survey and printing them. My usual approach to updating csv choice lists is to publish the csv to AGOL and then reference that list as linked content in the survey as outlined in https://community.esri.com/t5/arcgis-survey123-blog/survey123-tricks-of-the-trade-external-choice/ba...

Once you've done that you can update that csv using something like this:

 choice_list_itemID = [Item ID of the csv on AGOL]

choice_list_folder = [folder with the updated csv]

choice_list_name = [name of the updated csv]

choiceList = gis.content.get(choice_list_itemID)

choiceList_collection = FeatureLayerCollection.fromitem(choiceList) choiceList_collection.manager.overwrite(choice_list_folder + choice_list_name)