$datastore in arcpy.AddAttributeRule_management

755
3
Jump to solution
04-08-2020 04:07 AM
SreenivasaRaoPigili
Occasional Contributor

Hi All,

I have tested below Arcade expression in ArcGIS Arcade Playground and got error saying that $datastore variable is not found. To solve this issue, i have selected globals drop down value as "Attribute rule calculatoin" and script executed successfully.

var fsTerrainPolygon = FeatureSetByName($datastore,"Polygon",["COUNTRY_NAME"])
var fsIntersectCountry = Intersects(fsTerrainPolygon,$feature)
var fCountry = first(fsIntersectCountry)
if (fCountry == null)
return " "
return fCountry.COUNTRY_NAME

Now The same script, i am trying to utilize in the attribute rule creation. Please find the script below.


import arcpy
in_table = r"featureclass_path"
name = "CaptureCountryName"
script_expression = 'var fsTerrainPolygon = FeatureSetByName($datastore,"Polygon",["COUNTRY_NAME"]) var fsIntersectCountry = Intersects(fsTerrainPolygon,$feature) var fCountry = first(fsIntersectCountry) if (fCountry == null) return " " return fCountry.COUNTRY_NAME'
triggering_events = "INSERT;UPDATE"
description = "Capture CountryName From Python Script"
field = "COUNTRY_NAME"

arcpy.AddAttributeRule_management(in_table, name, "CALCULATION", script_expression, "NONEDITABLE", triggering_events, "", "", description, "",field)

Getting below error.
ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/support) to Report a Bug, and refer to the error help for potential solutions or workarounds.
Failed to execute (AddAttributeRule).

In the script_expression - if we give any arcade expression without globals, script is working without any issues.

(i.e  script_expression = 'if (1 == 0) {return "Fail"} else {return "Success" --> complete scripts executes without any issues}'

Please let me know, how can add execution profile for this script or how to resolve this issue.

FYI: Even alterattributerule management is also has same issue.

Thanks,

Sreeni.

0 Kudos
1 Solution

Accepted Solutions
SreenivasaRaoPigili
Occasional Contributor

Thank you Xander Bakker. Yes this helps. After we export to python script, we have to do a small change to the script.

Script will appear as below.

import arcpy
arcpy.management.AddAttributeRule(input_table, "test1", "CALCULATION", r'var fsTerrainPolygon = FeatureSetByName($datastore,"Polygon",["COUNTRY_NAME"])
var fsIntersectCountry = Intersects(fsTerrainPolygon,$feature)
var fCountry = first(fsIntersectCountry)
if (fCountry == null)
return " "
return fCountry.COUNTRY_NAME', "NONEDITABLE", "INSERT;DELETE", '', '', '', '', "COUNTRY_NAME", "INCLUDE", "NOT_BATCH", None, None)

The bolded and underlines single quote has to replace with multipline quote i.e """   """. This resolved the issue.

Thanks again.

View solution in original post

3 Replies
XanderBakker
Esri Esteemed Contributor

Hi pigili_sreenivasarao ,

The easiest way to solve this would be using the normal geoprocessing window, specify all the parameters there and validate the Arcade expression and run it. It it works, use the copy Python command option from the history window to get the correct syntax for this tool in a Python script.

SreenivasaRaoPigili
Occasional Contributor

Thank you Xander Bakker. Yes this helps. After we export to python script, we have to do a small change to the script.

Script will appear as below.

import arcpy
arcpy.management.AddAttributeRule(input_table, "test1", "CALCULATION", r'var fsTerrainPolygon = FeatureSetByName($datastore,"Polygon",["COUNTRY_NAME"])
var fsIntersectCountry = Intersects(fsTerrainPolygon,$feature)
var fCountry = first(fsIntersectCountry)
if (fCountry == null)
return " "
return fCountry.COUNTRY_NAME', "NONEDITABLE", "INSERT;DELETE", '', '', '', '', "COUNTRY_NAME", "INCLUDE", "NOT_BATCH", None, None)

The bolded and underlines single quote has to replace with multipline quote i.e """   """. This resolved the issue.

Thanks again.

XanderBakker
Esri Esteemed Contributor

Hi pigili_sreenivasarao ,

I'm glad you could solve the issue!

0 Kudos