Append Data in Nootbooks gives me "Object reference not set to an instance of an object" Error

1239
5
Jump to solution
03-24-2021 01:17 PM
AFackler_NAPSG
New Contributor III

I am making a notebook that will archive data by appending data into an existing feature layer. I have the data download as a geodatabase on ArcGIS Online and then append in. It has worked for me in the past, but today it's giving me a real hard time. Odd part is, It will run if there is no data in the existing target feature layer, but if there is data in the feature layer, then I get the "Object reference not set to an instance of an object" error. Code below, any help would be great, thanks!

exportCounty= counties.export(counties.title, "File Geodatabase")
exportCounty.download("/arcgis/home/")
exportCounty.id

countyLog=gis.content.search('title:County_Log', item_type='Feature Layer')[0]
countyLog

countyLog.layers[0].append(item_id=exportCounty.id,
upload_format='filegdb')

Output:

AdamFackler1_0-1616616711702.png

 

0 Kudos
1 Solution

Accepted Solutions
AFackler_NAPSG
New Contributor III

Okay for those who stumble across this and want an answer, I figured it out (with Esri help). There is a parameter in the append function called "Upsert". It is optional and defaults to "False"; this is what threw me off. If you do not include this, any feature that has the same geometry will fail to append. HOWEVER, if you add in "upsert=False" into the append, then it will stack the data if the target and source is the same fields (like I was trying to do). You will have to do some field matching coding if they are not the same. Upsert = True means you are overwriting/ updating existing data and you'll have to put in some other parameters.

AdamFackler1_0-1618586151698.png

 

View solution in original post

5 Replies
DanPatterson
MVP Esteemed Contributor
countyLog=gis.content.search('title:County_Log', item_type='Feature Layer')[0]

countyLog.layers[0].append(item_id=exportCounty.id,upload_format='filegdb')

 is countyLog the layer?  You seem to try to see what it is in the line below

did you try

countyLog.append(item_id=exportCounty.id,upload_format='filegdb')


... sort of retired...
0 Kudos
AFackler_NAPSG
New Contributor III

CountyLog is the existing layer I am appending data into. I tried taking out the .layer but got an error "'Item' object has no attribute 'append'". This is in ArcGIS Online Notebooks in case that matters.

AdamFackler1_0-1616622378307.png

 

0 Kudos
simoxu
by MVP Regular Contributor
MVP Regular Contributor

It seems CountyLog is an AGOL item rather than a FeatureLayer. 

Try CountyLog.layers[0].append(...)

 

0 Kudos
AFackler_NAPSG
New Contributor III

That's what I had originally and what is giving me the "Object reference not set to an instance of an object" Error.

0 Kudos
AFackler_NAPSG
New Contributor III

Okay for those who stumble across this and want an answer, I figured it out (with Esri help). There is a parameter in the append function called "Upsert". It is optional and defaults to "False"; this is what threw me off. If you do not include this, any feature that has the same geometry will fail to append. HOWEVER, if you add in "upsert=False" into the append, then it will stack the data if the target and source is the same fields (like I was trying to do). You will have to do some field matching coding if they are not the same. Upsert = True means you are overwriting/ updating existing data and you'll have to put in some other parameters.

AdamFackler1_0-1618586151698.png