Select to view content in your preferred language

How to detect that a new attachment has been added

1607
3
07-03-2018 05:13 PM
Trippetoe
Occasional Contributor III

I have a hosted feature service with attachments enabled. The service was created by uploading a file geodatabase.

We have a need to be able to tell programmatically when a feature has had an attachment added. 

I have Editor Tracking enabled on the feature service (Keep track of who created and last updated features), but adding an attachment to a feature seems to have no impact on the EditDate value of the feature.  In our file geodatabase we had Editor Tracking enabled on the __ATTACH table so presumably those fields made it into AGOL. However, i can't figure out how to access the __ATTACH table.

I am aware of the 'Keep track of created and updated features', but threads on geonet and the esri documentation seem to indicate that the property doesn't do anything yet, or perhaps is not accessible by applications using the python api?

My question is this: is there a way that i can programmatically (think python API) detect when a feature in a hosted feature service has had an attachment added to it?

thank you.

0 Kudos
3 Replies
KellyGerrow
Esri Frequent Contributor

HI Tom, 

You can do this by querying  to see if any attachment information is returned in the attachment infos of each feature.

Attachment Infos (Feature Service)—ArcGIS REST API: Services Directory | ArcGIS for Developers 

Trippetoe
Occasional Contributor III

Hi Kelly.

I wasn't aware of the 'Attachment Info' endpoint. Thanks for pointing that out to me. I played around with the endpoint for a bit,  but as best as i can tell i don't get information about creation date or edit date (those fields were part of the Attach table of the file geodatabase that i published to agol).  Additionally, the Attachments endpoint works on a per feature basis.  I am trying to discover features (if any) had a new attachment added since some previous date, e.g. in the last 7 days.  Is there a way to do something like that......As an example, the SQL query would look something like

SELECT features

FROM featureclass INNER JOIN featureclass__ATTACH ON featureclass.GlobalId = featureclass__ATTACH.parentGlobalId

WHERE featureclass__ATTACH.CreationDate > DATEADD(day,-7, GETDATE())

Thank you,

Tom

Trippetoe
Occasional Contributor III

Hi Kelly Gerrow

After your earlier clues, i tracked down the 'queryAttachments' REST endpoint.  That shows some promise but i am running into some unexpected behavior.  If i execute a query with the following parameter value:

Definition Expression: 1=1

I get the expect results - info about the attachments for all features with attachments. An abbreviated version of the response looks like this:

{       "parentObjectId" : 15,        "parentGlobalId" : "7432c245-6fd8-413a-b2d2-1d43a3dd15cf",               "attachmentInfos" : [         {           "id" : 1025,            "globalId" : "ee2e72a7-11b0-4310-af6b-212cd9a4efcd",            "name" : "Photo2.jpg",            "contentType" : "image/jpeg",            "size" : 660136,            "keywords" : ""         },

If i change the parameters to include 'Attachments Definition Expression' like below:

Definition Expression: 1=1

Attachments Definition Expression: name='Photo2.jpg'

I get an empty attachmentGroups element where i am expecting at least one record to be returned based on the previous response that shows 1 record with a name = Photo2.jpg. Instead, the response looks like this:

{   "fields" : [     {       "name" : "OBJECTID",        "type" : "esriFieldTypeOID",        "alias" : "OBJECTID",        "sqlType" : "sqlTypeOther",        "domain" : null,        "defaultValue" : null     },      {       "name" : "GlobalID",        "type" : "esriFieldTypeGlobalID",        "alias" : "GlobalID",        "sqlType" : "sqlTypeOther",        "length" : 38,        "domain" : null,        "defaultValue" : null     }   ],    "attachmentGroups" : [] }

In messing around with some of the other parameters like Size and Attachment Types, i see the expected behavior - only attachments that match the parameters are returned. Is the parameter 'Attachments Definition Expression' valid on the back end? If so, is there some special syntax i need to use?

** EDIT **

I played around a bit more and discovered that if i set the parameter

Attachments Definition Expression: 1=1

i get the expected results, i.e. all attachments, and if i set the parameter like so

Attachments Definition Expression: 1=2

i also get the expected results, i.e. no attachments returned.  So it seems like the parameter is valid, but i am not setting it correctly?

** END EDIT **

One more side question -- i see that there is an Attachment Info field 'keywords'; is there some place in AGOL where i can set\edit that value for each attachment?

thanks again for your help.