I'm trying to build an Arcade expression for an attribute that will flag features that have non-numeric values in the strings. Of course, the easier thing to do would be to have the field a long integer/short integer, yet this is over a systematically created field that is text string for the data type, yet the intent of the field for the field to NOT store any attribute values other than numeric
Below is an attribute rule expression built to simply root-out null values
return !IsEmpty($feature.Name)
Trying to replace !IsEmpty with a function helper to sift through the values to look for strings having anything other than numbers.
Thanks!
Solved! Go to Solution.
Remove the first two lines of code, since the code will end at that first return regardless of what you type in below it. You're correct in stating that it was just an example of how to find a non-numeric value.
You have also check whether the $feature.Name is a number before checking if it's a NaN (line 2).
if (Includes(["PAR", "OVERFL", "SBE"], $feature.Feature )){
return IsNaN(Number($feature.Name));
} else {
return true;
}
Thanks Ken!!
The only flaw with your rule expression is that I needed to insert an (!) in front of the IsNAN, as the attribute rule expression prompts the user to enter acceptance criteria for features that would pass acceptance. With having your code from the previous message, it flagged all of the features that had ONLY numeric characters, which was the opposite of what I needed the attribute rule to look for.
if (Includes(["PAR", "OVERFL", "SBE"], $feature.Feature )){
return !IsNaN(Number($feature.Name));
} else {
return true;
}
Thanks for all your help
Thanks, but how would I use it in an expression to enforce a dataset with thousands of records to have an attribute rule flag records that have any letters or non-numeric characters in the string?
It's for someone who wants to make sure all records are 1111111, 12345678, 88888888, etc and not mistakenly 1X111111, 1234567T, A8888888
I updated my answer to show how to test for a NaN.
Hmmm,
I just tried your solution, figuring you were giving me part of the coding I needed and baked it into my overall expression:
var test = Number("1a3");
return IsNaN(test);
if(Includes(["PAR", "OVERFL", "SBE"], $feature.Feature )){
return IsNaN($feature.Name);
} else {
return true
}
Unfortunately, it didn't seem to return any results in a test case. Is the "var" portion in your coding meant to give an example of what to look for as problematic?
Just trying to apply over the language you shared to my specific database, where a "Name" field is where the NaN values need to be examined over
Remove the first two lines of code, since the code will end at that first return regardless of what you type in below it. You're correct in stating that it was just an example of how to find a non-numeric value.
You have also check whether the $feature.Name is a number before checking if it's a NaN (line 2).
if (Includes(["PAR", "OVERFL", "SBE"], $feature.Feature )){
return IsNaN(Number($feature.Name));
} else {
return true;
}
Thanks Ken!!
The only flaw with your rule expression is that I needed to insert an (!) in front of the IsNAN, as the attribute rule expression prompts the user to enter acceptance criteria for features that would pass acceptance. With having your code from the previous message, it flagged all of the features that had ONLY numeric characters, which was the opposite of what I needed the attribute rule to look for.
if (Includes(["PAR", "OVERFL", "SBE"], $feature.Feature )){
return !IsNaN(Number($feature.Name));
} else {
return true;
}
Thanks for all your help