Hi Brains Trust. I've given up trying to figure this out on my own. I know that the arcpy Append GP tool will normally let me append data from a feature class to a feature service. However, when running the below code I keep getting the error displayed. Can anyone give me any pointers? I've tried working with Copilot, and also with different methods (e.g. da.updatecursor) but that doesn't work with feature services.
# Step 9: Compare and update Post_Planting_Inspection_Tracking_Base
print("Step 9: Comparing and updating Post_Planting_Inspection_Tracking_Base...")
arcpy.management.Append(
inputs=update_data,
target=post_planting_layer,
schema_type="NO_TEST",
field_mapping=r'Plantation "Plantation" true true false 50 Text 0 0,First,#,C:\temp\scratch.gdb\update_data,Plantation,0,50;Forest "Forest ID" true true false 6 Text 0 0,First,#,C:\temp\scratch.gdb\update_data,Forest,0,6;Species "Species" true true false 20 Text 0 0,First,#,C:\temp\scratch.gdb\update_data,Species,0,20;PlantingYear "Planting Year" true true false 0 Long 0 0,First,#,C:\temp\scratch.gdb\update_data,PlantingYear,-1,-1;RENDER_LABEL "Tenure" true true false 255 Text 0 0,First,#,C:\temp\scratch.gdb\update_data,RENDER_LABEL,0,50;PlantingFinished "Planting Finished" true true false 0 Date 0 0,First,#,update_data,MAX_FinishDate,-1,-1',
subtype="",
expression="",
match_fields="Plantation Plantation;Forest Forest;Species Species;PlantingYear PlantingYear;PlantingFinished MAX_FinishDate;RENDER_LABEL RENDER_LABEL",
update_geometry="UPDATE_GEOMETRY"
)
print("Features added/updated - process complete!")
Step 9: Comparing and updating Post_Planting_Inspection_Tracking_Base...
Traceback (most recent call last):
File "C:\Temp\Upload FPC416 Polygons.py", line 130, in <module>
arcpy.management.Append(
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 7306, in Append
raise e
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 7303, in Append
retval = convertArcObjectToPythonObject(gp.Append_management(*gp_fixargs((inputs, target, schema_type, field_mapping, subtype, expression, match_fields, update_geometry), True)))
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
RuntimeError: Object: Error in executing tool
>>>
Solved! Go to Solution.
Turns out the problem was the target "layer". I was converting my target feature service URL into a feature layer using the below command and that was the target. When I changed the target to the URL parameter, it worked! Now to figure out why the field mapping isn't working and my data is coming in with blank attributes!
post_planting_url = "https://services-ap1.arcgis.com/xyzxyzxyzxyzx/arcgis/rest/services/My_Feature_Service/FeatureServer/0"
post_planting_layer = FeatureLayer(post_planting_url)
Hi @LindsayRaabe_FPCWA, for the matching_fields option, are you using this parameter to update existing features?
Hi Jake. Yes, I believe I have (I am at least meant to have) the Update option enabled (including Geometry). I don't want duplicate records being created. Is there something missing in my code that should be there? From what I can see in the documentation, I have all parameters accounted for.
Turns out the problem was the target "layer". I was converting my target feature service URL into a feature layer using the below command and that was the target. When I changed the target to the URL parameter, it worked! Now to figure out why the field mapping isn't working and my data is coming in with blank attributes!
post_planting_url = "https://services-ap1.arcgis.com/xyzxyzxyzxyzx/arcgis/rest/services/My_Feature_Service/FeatureServer/0"
post_planting_layer = FeatureLayer(post_planting_url)