Select to view content in your preferred language

Arcade Expression - Calculate Field vs Validation Rule

741
2
Jump to solution
02-03-2023 02:08 AM
TitusGian
New Contributor

I am trying to sieve out duplicate values within the column "ID" from the table "IDs" and am getting different results for using the same arcade expression with Calculate Field tool and Validation Rule. The expression gives the intended output for the Calculate Field tool but Validation Rule outputs Error 002717, at line 3, where it seems to suggest that it is unable to read the  ${id} variable. I have also tried the method of adding the string with the variable id to no avail.

 

var tbl = FeaturesetbyName($datastore, "IDs", ["ID"], false);
var id = $feature.ID
var query = `ID = ${id}`;
var countID = Count(Filter(tbl, query));
function isDup(value){
     if (value > 1){
         return false;
     } else {
         return true;
     }
}
isDup(countID)

 

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

Do you have empty id values? In that case, your query would be "ID = ", which is an invalid query.

var id = $feature.ID
if(id == null) { return false }  // feature is invalid if no id
var tbl = FeaturesetbyName($datastore, "IDs", ["ID"], false);
var query = "ID = @ID";  // try using this notation instead
var countID = Count(Filter(tbl, query));
return countID == 1  // valid if exactly 1 feature has this ID, else invalid

Have a great day!
Johannes

View solution in original post

0 Kudos
2 Replies
JohannesLindner
MVP Frequent Contributor

Do you have empty id values? In that case, your query would be "ID = ", which is an invalid query.

var id = $feature.ID
if(id == null) { return false }  // feature is invalid if no id
var tbl = FeaturesetbyName($datastore, "IDs", ["ID"], false);
var query = "ID = @ID";  // try using this notation instead
var countID = Count(Filter(tbl, query));
return countID == 1  // valid if exactly 1 feature has this ID, else invalid

Have a great day!
Johannes
0 Kudos
TitusGian
New Contributor

There weren't any empty records. But the query fix you suggested worked for line 3 of the original code. 

Thank you so much, @JohannesLindner !

0 Kudos