Greetings. I'm trying to create an attribute rule to automatically name objects when they are created. Our naming convention requires using an asset id grid where the grid name is incorporated into the asset name. I written an Arcade Expression that works when calculating a field. When I then try to use that same expression as code in an attribute rule, I get a 002717 error indicating an unexpected null value. I tried submitting or Arcade expressions that are much simpler and also get the same error. I don't understand why the code runs without issue in the calculate field tool, but kicks back an error when being used as an attribute rule. I understand I am not adding the code properly in the forum, I cannot seem to find the right way to add it. I'm adding the code in the text below.
var agrid = (FeatureSetByName($datastore, 'DBO.CAIDGD', ['Utility_ID']));
var gridid = First(Intersects(agrid, $feature));
return gridid.Utility_ID;
The above three lines of code work in the calculate field, but do not pass as an attribute rule. The above code is simplified in a much larger script as a single line of code below.
var currentValue = First(Intersects(FeatureSetByName($datastore, 'DBO.CAIDGD',['Utility_ID']),$feature)).Utility_ID;
In the larger script, the above code is the line identified with the 002717 error when I try to use the script in an attribute rule calculation rule.
Thanks all.
@PCWRGIS
For it to work you need to have check for a null return on your FeatureSetByName before passing into First and Intersects otherwise the code will not validate in an attribute rule.
Give this a try.
var agrid = (FeatureSetByName($datastore, 'DBO.CAIDGD', ['Utility_ID']));
if (count(agrid) == 0) return;
var gridid = First(Intersects(agrid, $feature));
return gridid.Utility_ID;
Here is another example. If not you may want to try and make a post in the ESRI community specifically used for Attribute Rule related questions.
// Create feature set to the intersecting class
var intersecting_featset = FeatureSetByName($datastore, 'DBO.CAIDGD', ['Utility_ID'], false)
// Intersecting the feature with the feature set and retrieve the first feature
var intersected_feature = First(Intersects(intersecting_featset, $feature));
// Check to make sure there was an intersected feature, if not, return
if (IsEmpty(intersected_feature) || intersected_feature == null)
{
return null;
}
return intersected_feature.Utility_ID