Select to view content in your preferred language

Attribute rules for enforcing attachments?

2403
13
01-27-2020 04:27 AM
AndrewZimba1
Regular Contributor

When building services for Collector with feature classes in an enterprise gdb, are attribute rules the appropriate mechanism for enforcing the inclusion of a .jpg attachment to a point and returning an error message if a save attempt is made without such an attachment?

0 Kudos
13 Replies
HusseinNasser2
Esri Contributor

Attribute rule is one way to enforce this. You should be able to add a constraint rule to the attachments table of your class that prevents adding a row to the attachment table if the extension is not jpg. You could then publish the class as a feature service to ArcGIS Enterprise and consume it from collector. (Attribute rules not supported on ArcGIS Online yet)

Here is an example

Here is an example script

//if the extension is jpg allow the edit, else don't allow the edit. 
if (right($feature.ATT_NAME, 3) == "jpg") return true

return false

The attachment will only be added if the file has a `jpg` extension. There might be a bug where you won't get a meaningful error message back today. We might be able to get to that in the future where the actual error message comes back.

AndrewZimba1
Regular Contributor

Right on.  Now it seems that will enforce the attachment type, but it won't enforce that a point must have an attachment, right?

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Andrew Zimba ,

Arcade provides the Attachments function which will return an array of the Attachment types. The problem is that these functions and types are not available in the Attribute rule profile (yet?). Normally you would do a Count and if the count is larger than 0, you could check the content type.

There might be a way using a FeatureSetBy* in combination with Filter to get to the result, but it would be better to have the Attachments function and Attachment type available in the attribute rule profiles. 

HNasser-esristaff ; any idea if that is on the roadmap?

0 Kudos
XanderBakker
Esri Esteemed Contributor

There is an example attribute rule (constraint) here by mmiller-esristaff that could help get started:

arcade-expressions/reject_too_many_related.md at master · MikeMillerGIS/arcade-expressions · GitHub 

0 Kudos
AndrewZimba1
Regular Contributor

I'll check it out.  Thanks!

0 Kudos
HusseinNasser2
Esri Contributor

Thanks Xander!

The Attachments arcade function is actually supported on the Attribute Rules profile, we will just need to update the documentation to reflect that. Good find! So yes one can prevent a feature from being created/updated if no attachments was found. However I see this rule fits more as Validation rule instead of a constraint rule (Generating errors for existing features with no attachments)

AndrewZimba1
Regular Contributor

Something here I'm not getting.  I'm attempting to implement as a Validation rule.  Here's the rule setup:

On save it throws Error 001946: The input workspace type must be branch version.

Not sure what is going on here.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Andrew Zimba ,

Not sure if branch versioning is required to implement this type of attribute rule. Hussein Nasser ; can you confirm?

What you do need to know is that you should check using "count" and not comparing it to null. If you do not have attachments, it will return an array with no items, yet it will not be null.

Since you want to check for jpg attachments, see the example below that will only check this content type and in this example I also check for the images size between 1M and 5M bytes.

var options = {"types": ["image/jpeg"],
               "minsize": 1000000,
               "maxsize": 5000000}
var atts = Attachments($feature, options);
if (Count(atts)==0) {
    return false;
} else {
    return true;
}
0 Kudos
HusseinNasser2
Esri Contributor

Apologies I should have mentioned that and Thanks Xander Bakker‌ for reminding me. Yes Validation and Batch Calculation rule are only supported Enterprise Geodatabase Datasets registered with branched versioned. We are bringing the support of File Geodatabase to these type of rules in the upcoming releases soon.