Select to view content in your preferred language

Calculations occuring after point submission, not on point creation

838
6
08-03-2023 11:55 AM
FletcherHubbard
New Contributor II

Hello. I've been running into a consistent issue where photos are not always attaching to my points correctly, despite the device stating that it submitted. In response, I've been attempting to create a control method that is usable on the field, in real time, offline. The code I have so far is as follows:

var AtchNum = Count(Attachments($feature))
if ($editcontext.editType) {return AtchNum}
else {return '0'}
 
The issue I'm encountering is that the calculation only occurs at point creation, not point submission. This is important because it returns 0 every time because the moment the point is created, there is no data therefore the return is 0. But I need it to return a nonzero answer. My var creates this number, and the purpose of the editcontext feature is supposed to be to force the code to recalculate when the point data is updated, such as when a photo is added. This feature doesn't appear to be working however, and I can find no explanation on how to properly use this variable.
0 Kudos
6 Replies
FletcherHubbard
New Contributor II

Hey, just realized I had a typo in this post. My code is not accurate. the if line is actually: 

if($editcontext.editType=="UPDATE") {return AtchNum}

0 Kudos
JustinReynolds
Regular Contributor

@FletcherHubbard 

There are a couple things going in your expression.

First, what your are experiencing with attachment counts on INSERT is by design and is an unfortunate limitation. You cannot currently access attachments until after the feature is created. Before the feature is created, there are no attachments to retrieve from the mobile geodatabase.

So we would expect the statement below to always return 0 if your editcontext.editType is "INSERT".

 

Count(Attachments($feature));

 

 This would be the case on INSERT no matter the number of attachments your have added.  In the documentation for the Attachment function the input parameter description is as follows:

  • inputFeature: Feature - Attachments associated with this feature will be fetched from the service.

This means that you cannot fetch attachments from a feature that does not exist. This also extends to on the "UPDATE" edit event.  If you are editing an existing feature and add new attachments during your edit session, it will not count those new attachments because they have yet to be submitted to the database.

When ESRI introduces inline attachment elements, my guess is that the runtime will handle this differently so that we can determine how many attachments have been added to the current edit session, prior to submission, but this is not how the Attachment function works at the moment.

Second, in your if statement, you should probably be testing for the type of edit event. The profile variable $editcontext.editType does not return the expected Boolean value expected by itself.

 

if ($editcontext.editType) { return AtchNum };

 

 vs.

 

if ($editcontext.editType == 'INSERT') { return AtchNum };

 


If your expression was to do what you needed in the future, it could also be simplified to something like the following:

 

if ($editcontext.editType == 'INSERT') { return Count(Attachments($feature)) };
return 0;

 

- Justin Reynolds, PE
0 Kudos
FletcherHubbard
New Contributor II

I see, that is extremely helpful. So then creating a feature in Arcade that updates on submission simply isn't possible right now. What if the code is implemented into post-processing labeling? Say, if I implement that code that is currently Arcade into the Layer labeling by converting it to SQL, so that it works offline? What would that conversion even be? I'm not familiar with SQL, so I don't know what the equivalent of Count(Attachments($feature)) would be.

0 Kudos
JustinReynolds
Regular Contributor

Correct.  The Attachment function doesn't have much utility in the Form Calculation profile at the moment.  That could change or ESRI could introduction additional functionality when inline attachments elements become a thing in 2024 or 2025.

The Attachments function does however work great for popups, and you should be able to get a count to display in your label using Arcade as well.  It should work offline with your own edits or edits from others once you sync up with the server.

The option of last resort would be to use an automated task to calculate that field for all of your features daily or weekly.  Python or FME come to mind for that, but would require that you sync your offline map often as well.  We use webhooks and FME on our services a lot for making special changes to data or triggering other event as new features are submitted.

- Justin Reynolds, PE
0 Kudos
FletcherHubbard
New Contributor II

Hey Justin, I'm thinking we've had a disconnect. To my knowledge, when creating new fields from the data section in ArcGIS proper and asking said fields to perform calculations, it restricts offline mode from being used if the code is in Arcade. It only allows for the field to work offline if the code is written in Sequel. I've not heard of and am unfamiliar with creating what I'm attempting to do in popups in the Field Maps Viewer. My end goal is getting every point to have a number floating above it that is that number of attachments. 

0 Kudos
kmsmikrud
Regular Contributor

Hi @FletcherHubbard ,

I just wanted to add in we have been using arcade expression in pop-ups in Field Maps offline that work great. Here is a link on attachments and arcade that might be useful. 

https://www.esri.com/arcgis-blog/products/arcgis-online/mapping/visualize-your-attachments-in-arcgis...

AttachmentCount_arcade.png

I think the arcade expression should also work in labels offline for attachment count. 

Thanks,
Kathy

0 Kudos