Automating Calculations and Constraints with Attribute Rules

Blog Post created by tdewitte-esristaff Employee on May 7, 2018

Improve Data Quality and Editor Productivity


By Tom Coolidge and Tom DeWitte

Gas utilities continue in an era where the number of gas utility employees is decreasing while the number of customers is increasing.  Just over the last couple decades, the customers to employee ratio in the gas industry has more than doubled!  This means each gas utility employee is expected to carry a bigger work load.


At the same time, regulatory and business forces are increasing the level of detail required in defining assets and driving data collection and reporting activities from paper-based solutions to digital.  These trends are evident in new and proposed regulations like Tracking and Traceability, and in common workflows like weld inspections and daily reporting.  How are the gas utility GIS system managers and editors to maintain their productivity with an ever-increasing list of information to manage and attributes to populate? Part of the answer to this challenge is attribute rules.


What are Attribute Rules?

                Attribute rules are a new geodatabase capability added with the recent 10.6 release of ArcGIS. They provide the ability to enhance the behavior of a feature class attribute within an enterprise geodatabase. One example of an attribute rule is for the GPSX, GPSY, GPSZ attributes of a gas fitting to be automatically populated with the geometry’s X,Y, and Z values when the fitting is initially created by an editor. Another example is to constrain the operating pressure of a pipe segment to a specific range based on its engineering system type and material values. A pipe segment with an AssetGroup = Distribution Pipe and a Material = PE2708 cannot have an operating pressure more than 200 psi. If an editor attempts to submit a pipe segment with an operating pressure of greater than 200 psi to the geodatabase, the geodatabase will reject the edit. The reason the geodatabase rejects the edit is because attribute rules are a property of an enterprise geodatabase feature class.

Another example of attribute rules is the population of attributes such as a pipeline construction Daily Reports TOTALLENGTH.Field supervisors need not worry about this attribute being maintained, or getting out of sync with the entered survey staking from and to measures, because the attributes rules are automatically doing the math.


Is this another ArcGIS Pro Only Capability?

                No. Attribute rules are a server-side capability. They work not only with ArcGIS Pro 2.1, they also work with the current releases of ArcGIS Server feature service editing clients like Portal’s map viewer, web application builder web apps and Collector.


How Does it Work?

                The initial release of attribute rules with ArcGIS 10.6 supports two types of rules:

-Calculation rules

-Constraint rules

Calculation rules will automatically populate the attribute based on the defined calculation. Any combination of the record’s other attributes can be used in the calculation. For example, PIPEVOLUME can be automatically populated by using the pipe segment’s DIAMETER and geometry length to calculate the cylindrical volume.

                PipeVolume = 3.14.16 * (DIAMETER/2)2 * Shape Length

Another more complex example is the collection of a pipe’s ASTM F2897 barcode. The barcode can be scanned and captured by standard field data collection applications, such as Collector for ArcGIS.  Attribute calculation rules can be applied to parse the barcode, translate the values from base62 to base10 and then write the decoded information to the appropriate attribute fields such as manufacturer, manufacturer model diameter, wall thickness and material. That is an advanced arcade script, which I will save to discuss in another blog.

Constraint rules go beyond the capabilities of range domains and coded value domains in that they are not limited to being constrained to only the record’s subtype values. Any combination of the record’s other attributes can be used to define the attributes valid value. 


How Do I apply Attribute Rules?

                Attribute rules are applied using the ArcGIS Pro geoprocessing tool called “Add Attribute Rule.” The logic of the rule is written with the Arcade scripting language. One approach to applying attribute rules is to use the following primary steps:

  1.  Use the Geoprocessing tool “Calculate Field” to create, validate syntax, and test the logic of the arcade script.
  2. Use the geoprocessing tool “Add Attribute Rule” to apply the tested and validated arcade script to a feature class’s attribute.

Applying Attribute Rules to Construction Daily Reports

                An example to introduce this capability is the automating of the tabulation of Total Length of a Construction Daily Report. Construction Daily Reports are a construction industry staple for communicating the progress of a project to managers and executives.  I remember very clearly as a young engineer, having to fill out this form to let my office based project members know what was happening at the construction site.  This is usually a single page paper document.  In pipeline construction, common information collected in this document would be:

                - What task did my crew work on today? (Surveying, clearing, welding, trenching, etc)

     - How much was accomplished? (Today, my crew trenched from survey stake 1450+00 to 1650+00)


Converting this type of paper-based form into a digitally-collected form is not difficult.  Seamlessly prepping this information into a structure that can be easily and accurately entered by the field supervisor and dynamically consumed by a project’s manager’s dashboard takes a little more thought and automation.  This is where attribute rules can help with the automation.  Specifically, with the dynamic calculation of the field crew supervisor’s manually entered start and end measure locations.  Relying on a user entered polyline geometry is not a very accurate method.  Remember that the crew supervisor is filling out this form at the end of the day, most likely while sitting in the construction trailer or in their truck.  Using GPS to create the geometry is not an efficient option as already noted, at the time the form is filled out the sup.  Having the field supervisor use his or her finger to mark on the small digital screen to denote start and finish is not accurate enough.  What is an accepted practice is to denote start and finish based on the survey stakes along the construction path.  The stakes are marked with a continuous measurement from the construction project start location.  With this understanding what we need is a simple calculation to determine the length of the daily accomplished task based on the supervisor’s manually entered start and end measures.


                FromMeasure – ToMeasure = Total Length of task completed


In Arcade this would be written as follows:


$feature.TOMEASURE - $feature.FROMMEASURE


To help avoid issues with the field supervisor entering a larger FROMMEASURE than the TOMEASURE the application of an absolute value function to the “total Length of task completed” should solve the problem. The arcade version of that would be written as follows:


Abs($feature.FROMMEASURE - $feature.TOMEASURE)


Next step in this automation is to include some basic situational error handling for a situation where someone after the initial daily report entry, accidentally clears the FROMMEASURE or the TOMEASURE.  We do not want to lose the calculated TOTALLENGTH.  So, the arcade expression gets modified as follows:


if ($feature.FROMMEASURE == null)  {

return $feature.TOTALLENGTH}

else if ($feature.TOMEASURE == null)  {

return $feature.TOTALLENGTH}


return Abs($feature.FROMMEASURE - $feature.TOMEASURE) 


After testing this with the CALCULATE FIELD geoprocessing tool to test and verify the arcade syntax, it is time to apply this to the geodatabase.


Adding the Attribute Rules to the Geodatabase

                Within ArcGIS Pro is a geoprocessing tool called “Add Attribute Rule”.  Like other schema changes in the geodatabase, you must be the data owner to perform this change.  When defining this attribute rule, you define specifically what types of edit changes to the record should invoke the attribute rule. These are called Triggering Events.  There are three type of triggering events: Insert, Update, and Delete. 



For this rule I will select both Insert and Update. 


Another property of the attribute rule is to define whether the field which is being automatically populated should allow editors to manually update the field and overwrite the tabulated value, or should the field be designated as read-only and only the attribute rule itself can populate the field.


For this attribute rule, I will uncheck the “is Editable” option to make this TOTALLENGTH attribute a read-only attribute.

The last step is to load in the arcade script that was successfully tested with the CalculateField GP tool.


With the attribute rules specified and the arcade script loaded, the tool is ready to be run.


What does the Attribute Rule look like to editors?

Attribute rules are meant to be stealthy.  They run silently and are not meant to be seen. 

For editors, the process of editing just got a little simpler. One field that was a manual user entry field is now an automatically populated field.  Notice in the screen shot below of my web application builder web application that in the attribute edit form, the field Total Length is greyed out.


Although my example is not overly complex, the impact of this little bit of automation is significant.  With the Total Length now automatically populated with the edit is submitted.  Follow-on applications like Dashboards get simpler to deploy with real-time representation of the data. The Dashboard below provides a real-time summary of the progress of a pipeline construction project.  The values are tabulated directly from the Daily Reports.  Confidence in the summary is greater given that the computer is doing the math.  And there is no need for nightly batch processes to run the tabulations, simplifying the setup and administration of this dashboard.



                Remember attribute rules work with existing ArcGIS platform clients which can edit a 10.6 or higher enterprise feature service.  This includes mobile apps like Collector for ArcGIS, office web applications like Portal’s web application builder and map viewer, and desktop applications like ArcGIS Pro.


Attribute rules provide new capabilities to improve the quality of your data, improve the productivity of your editors, and simplify the data entry process thru automation.  If you have not yet tried attribute rules, you may be missing the opportunity to be the Rock star of the month at your company by improving the data entry processes.