Unable to create a GP service to generate Survey123 feature reports

541
1
07-22-2020 05:30 PM
BradSnider
New Contributor II

Hi, I'm attempting to use the arcgis Python API to create a GP service to generate S123 feature reports, and simply return an array of item ids.  The code below runs, but it does not appear to be generating a new report.  The only two items in the survey.reports array are the template (not sure why it'd even show up), and a report previously generated directly from the S123 website.

I'm also not seeing any new items under My Content in AGOL.

Any tips?

Thanks!

Brad

    survey = arcpy.GetParameter(0)  # '0d87ba0b72cf4c32b35c1db4d58c370d'
    username = arcpy.GetParameter(1)  # '<un>'
    password = arcpy.GetParameter(2)  # '<pwd>'
    template = arcpy.GetParameter(3)  # 3
    where = arcpy.GetParameter(4)  # '"objectIds":"3,4"'
    utc_offset = arcpy.GetParameter(5)  # '-07:00'
    title = arcpy.GetParameter(6)  # 'My_Report'

    gis = GIS(None, username, password)
    sm = SurveyManager(gis)
    survey = sm.get(survey)
    template_id = survey.report_templates[template].id
    survey.generate_report(survey.report_templates[template], where, utc_offset, title)
    report_id_arr = []
    for report in survey.reports:
        arcpy.AddMessage('doc id: ' + report.id)
        if report.id != template_id:
            report_id_arr.append(report.id)
    report_ids = '["' + '", "'.join(report_id_arr) + '"]'
    arcpy.AddMessage('doc ids: ' + report_ids)
    arcpy.SetParameterAsText(7, report_ids)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
1 Reply
ZacharySutherby
Esri Regular Contributor

Hello Brad, 

I have tested the workflow and was able to reproduce the same behavior. The quick answer why nothing is being returned is because the string in the “where” parameter is incorrect. The string that I have gotten to work for generating a report against multiple OID’s was 'objectid=1 OR objectid=2'. In short the “where” parameter is looking for the same syntax as the Where clause when querying a layer from REST. If you enter Where: objected=1,2 from REST the request will return an invalid parameter error. If you use Where: objectid=1 OR objectid=2 the query will return both of those Object ID’s.

 

I had made one modification to the script for it to work in my environment which was to change the survey manager function to arcgis.apps.survey123.SurveyManager(gis) instead of SurveyManager(gis).

 

I have attached a copy of the script I have been testing with to the email in case it is helpful for testing.

Thank you, 

Zach

Thank you,
Zach
0 Kudos