AnsweredAssumed Answered

Update Service Definition on AGOL

Question asked by InyoCounty on Jan 5, 2018
Latest reply on Jan 8, 2018 by InyoCounty

Using the script at this blog: https://blogs.esri.com/esri/arcgis/2017/03/14/updating-your-hosted-feature-services-with-arcgis-pro-and-the-arcgis-api-for-python/

Line 41: sdItem = gis.content.search("{} AND owner:{}".format(sd_fs_name, user), item_type="Service Definition")[0]
returns the wrong Service Definition (SD). The title query is not strict enough, so it returns any SD with a "Z" in the title. The SD I'm looking for is Zoning.

 

Title or owner can be replaced with id:
sdItem = gis.content.search(query="title:"+ sd_fs_name + " AND id:" + serviceItemID, item_type= "Service Definition")[0]
which throws: IndexError: list index out of range


Many permutations have been tried for using ID.

If item_type= "Service Definition" is removed, line 41 will run:
sdItem = gis.content.search(query="title:"+ sd_fs_name + " AND id:" + serviceItemID)[0]

However, then on line 45: fs = sdItem.publish(overwrite=True)
it throws:
File “C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis.py”, line 3125, in publish
if fileType == ‘shapefile’:
UnboundLocalError: local variable ‘fileType’ referenced before assignment

 

So, the question is - how do I specify the ID, and also specify the item type?

Outcomes