Select to view content in your preferred language

Attribute rules causing failures in field calculations

1596
8
02-19-2020 12:11 PM
SamSzotkowski1
New Contributor

I've implemented some attribute rules for a feature class to calculate immediately on insert and update.  I know the rules work because when I manually edit the table, or use arcpy.UpdateCursor() to iterate through the table, the rules are enforced.  The problem comes when I try to use Calculate Field(s) geoprocessing tool I get an Error 999999 and an "Arcade error: Field not found" for a field that definitely exists.  I've attached one of the rules and the error message.  Notably there's no GlobalID listed in the error message despite the fact that all the features have a GlobalID.

Any thoughts why this happens?  For now I'm just disabling attribute rules but I'd like to figure out what's happening. I'm using ArcGIS Pro 2.4.3.

8 Replies
SeanSummers_CC
Regular Contributor

I have run into a similar problem with Calculate Fields.  I wrote my expression in Arcade but never changed the expression type from Python (it is Python by default).  Once I changed the expression type to Arcade it fixed the problem.  Just a thought of something to check.

HusseinNasser2
Esri Contributor

Hey Sam

are you still running into this problem? We would like to take a closer look and reproduce in the latest software. Can you send us file gdb of a sample data that repro ? would appreciate it

It is ok to use PYTHON to calculate your expressions because that will eventually trigger an update on the row which will execute the attribute rule. 

Thanks

Hussein

0 Kudos
matt_g_g
Emerging Contributor

Did this ever get resolved? I'm experiencing the same issue in Pro v3.2.1.

matt_g_g
Emerging Contributor

Sorry, should have included a bit more info before hitting submit!

If I try to run calculate field from the attribute table I get an error in regard to the attribute rules setup on the table but if I use an update cursor via arcpy.da module then I don't get an error and everything executes as expected.

0 Kudos
LanceKirby2
Frequent Contributor

Any chance you resolved your issue? I'm encountering something very similar in Field Maps. Tagging @HusseinNasser2 if you have any insight.

0 Kudos
HusseinNasser2
Esri Contributor

posted a workaround ,can you try? 

0 Kudos
LanceKirby2
Frequent Contributor

Hope this helps @matt_g_g. If you have a moment @HusseinNasser2 my issue is a little different.. I can point you over to this thread if you would be willing to offer some advice. https://community.esri.com/t5/arcgis-field-maps-questions/field-maps-constraint-rule-feature-form-ca.... It would be much appreciated!

0 Kudos
HusseinNasser2
Esri Contributor

Can we try the following? 

 

When running python on a class with attribute rules you must specify all the fields required by the attribute rule in the python cursor. 

Here is an example 

I have a table with three fields a,b, and c.

Field c has an attribute rule return $feature.b * 2. So the rule require fields b and c

Because b and c are required by the attribute rules those fields must by passed to python as follows.

 

 

 

 

def update_standalone(fields):
    with arcpy.da.UpdateCursor(str(gdb / 'standalone'), fields) as cursor:
        for row in cursor:
            row[0] += 1
            cursor.updateRow(row)


print('Running')
update_standalone(['a', 'b', 'c'])  # Succeeds 

# passing only a will fail
# update_standalone(['a'])  # RuntimeError: Failed to evaluate Arcade expression. 
# passing only b will also fail 
# update_standalone(['b'])  # SystemError: <method 'updateRow' of 'da.UpdateCursor' objects> returned NULL without setting an error
# passing all fileds or the required fields for attribute rules will succeed
# update_standalone(['a', 'b', 'c'])  # Succeeds 
# update_standalone(['b', 'c'])  # Succeeds
print('Done')

 

 

0 Kudos