We have had issues with sync failing at times when our inspectors return from the field. This seems to happen for various reasons. When it does we have to do quite a bit of manual loading of data to our data collection layers in Arc Online. The biggest hassle is with the attachments. I can add attachments using the global id of the feature in the service in AGOL and related global id of the attachments once they are taken from the runtime GDB to a local folder. My issue currently is with handling features that already have the necessary attachments. Especially those features that have more than one attachment.
I am not a python expert but have gotten this far using the API it would be nice to have something to automate this task when we have this issue.Michael Kelly any thoughts would be much appreciated.
Currently the script runs fine when there are no attachments or it needs to add only one more attachment to a feature. The issue comes when multiple attachments already exist. Whatever I am doing is not iterating past the first attachment it finds so it adds duplicates. In particular lines 34-37. It finds the name of the existing attachment and matches it to the filename but only for the first attachment of a particular feature. I am hoping this is just something simple I am missing. General pointers on organization of for and if statements would be greatly appreciated.
Solved! Go to Solution.
Hi Robert,
I'm not sure what the end goal is here - is it to loop through folders stored locally on disk (in a format similar to how the Download Attachments script downloads attachments) and add attachments to associated features hosted in ArcGIS Online if they don't already exist?
It's hard to debug the above code by just seeing a snippet. From reading through the code, lines 48 and 49 don't appear necessary - I'm not sure what if statement the else statement relates to.
What error message are you getting back? Python can also be very picky when it comes to syntax so I would suggest you keep your comments in line (e.g. lines 40 and 42).
By the sounds of it, what you need to do is get a list of all attachments associated with a particular feature (you appear to be doing this in line 27). However after that you are not looping through the file names in this, only comparing with the first file name returned. Something like this may do it:
if attachmentName not in attachmentsList:
#add attachment to feature
It's been a while since you posted this so perhaps you made some ground in the meantime?
Michael
Hi Robert,
I'm not sure what the end goal is here - is it to loop through folders stored locally on disk (in a format similar to how the Download Attachments script downloads attachments) and add attachments to associated features hosted in ArcGIS Online if they don't already exist?
It's hard to debug the above code by just seeing a snippet. From reading through the code, lines 48 and 49 don't appear necessary - I'm not sure what if statement the else statement relates to.
What error message are you getting back? Python can also be very picky when it comes to syntax so I would suggest you keep your comments in line (e.g. lines 40 and 42).
By the sounds of it, what you need to do is get a list of all attachments associated with a particular feature (you appear to be doing this in line 27). However after that you are not looping through the file names in this, only comparing with the first file name returned. Something like this may do it:
if attachmentName not in attachmentsList:
#add attachment to feature
It's been a while since you posted this so perhaps you made some ground in the meantime?
Michael
Hi Michael - Issue was each object ID and its attachments writes to a separate list when you attachments.get_list(oid). Maybe that is obvious but it was what created the issue for me. So in order to catch all of the existing attachments I had to first create a comprehensive list before going to check against the files I wanted to attach. Earlier I could not understand why it would catch some existing ones and attach others. Thanks for getting back to me. This is not a super common work flow for us but it is something that does come up so being able to batch add attachments to appropriate features of a feature layer is helpful.
Thanks for your time!
Rob
Hi Rob,
Very good - glad you got it sorted. I'm sure others have similar workflows - it would be great if you could share your work with the community via GitHub. This is the repository where I shared my script.
Kind regards,
Mikie
Ok thanks Mikie. I put it here Add-Attachments/Add_Attachments_GlobalID.ipynb
I am not very familiar with GitHub and posting things so if its worthwhile for me to change anything let me know.
Thanks
Great thanks Robert - I'm sure there are many who will find this useful