Hello,
I am trying to set an Attribute Rule in ArcPro. I am receiving "Invalid expression. Error on line 1. Field not found Cleanliness_Rating.
I have a field (Cleanliness_Rating) with a text value (from a Domain) of 1-xyzxyzx... , and I want it to slice the first value (1) and return it as a number.
I have test data in the fields. Am I missing something that will allow the field to be found?
Thanks,
Solved! Go to Solution.
Try using bracket notation, $feature['Cleanliness_Rating']. Dot notation works most of the time, but bracket notation works all the time.
Also, Arcade isn't Python, so it's really not going to work that way. What you want is the text function Mid for getting text out from the string, or Left to get the first character. Try this instead:
Left($feature['Cleanliness_Rating'], 1)
Try using bracket notation, $feature['Cleanliness_Rating']. Dot notation works most of the time, but bracket notation works all the time.
Also, Arcade isn't Python, so it's really not going to work that way. What you want is the text function Mid for getting text out from the string, or Left to get the first character. Try this instead:
Left($feature['Cleanliness_Rating'], 1)
This makes sense. I have tried two different configurations of the above idea:
var firstChar = Left($feature['Cleanliness_rating'],1)
var result= Number(firstChar);
result
This results in "Invalid expression. Error on line1. Object not found cleanliness_rating
var firstChar = Left($feature['Cleanliness_rating'],1)
var result= Number(firstChar);
result
This results in "Invalid Expression. No features found."
I also tried the below idea with this:
var firstChar = Cleanliness_Rating($feature,[Cleanliness_rating],1)
var result= Number(firstChar);
result
The results in "Invalid expression. Error on line 1. Unknown function"
Yeah, that third option won't work unless you define the function first.
Those errors on the first two seem strange. Are you positive you're typing the field name correctly?
Let's do some debugging. Can you add some Console statements to the top of your expression and see what it spits out?
Console($feature)
for (var attribute in $feature) {
Console(attribute, $feature[attribute])
}
Console($feature['Cleanliness_rating'])
Alright, my test data was corrupted. I reloaded the data and we are good to go. The below expression is valid and functioning:
var firstChar = Left($feature['Cleanliness_rating'],1)
var result= Number(firstChar);
result
Thank you everyone for the help. I learn something new everyday.
Two quick thoughts:
var firstchar = $feature.cleanliness_rating;
var extractsubstring = Left(firstchar,1);
var result = Number(extractsubstring);
return result;
There wasn't a space after "Text"
The above expression results in the message "Invalid Expression. No features found"
You mentioned you are using domain for that field:
"I have a field (Cleanliness_Rating) with a text value (from a Domain) of 1-xyzxyzx..."
To get the descriptive value, you should use DomainName($feature, 'Cleanliness_Rating'), please give it a try.
https://developers.arcgis.com/arcade/function-reference/feature_functions/#domainname
I gave that a try:
Cleanliness_Rating($feature. 'cleanliness_rating')
This results in " Invalid expression. Error on line 1. Identifier expected"