We are creating an indicator using an arcade script in a dashboard. The problem is that when calling the count() function over the feature set then it gives the true number of records, while when applying a "for" loop {for(var i in featureSet)} to increment a counter that was initialized to 0 then the final value of the counter is greater than the real number of records. Note that the same problem is happening on the main layer and on the relate table (sublayer) too. So, how to solve this and what is the reason behind it?
//here is the code of the right answer of the number of records
var database = FeatureSetByPortalItem(Portal('link'), 'id',1)
//last parameter is 1 as I need to access the first sublayer
//knowing that the same problem appears when trying to access the main layer with parameter 0
return count(database)//here is the wrong answer of the number of records
var database = FeatureSetByPortalItem(Portal('link'), 'id',1)
//last parameter is 1 as I need to access the first sublayer
//knowing that the same problem appears when trying to access the main layer with parameter 0
var c = 0
//c is the counter of the number of records
for(var i in database){
c=c+1
}
return c
Arcade Expression in Dashboard
This screenshot shows the problem of how these two codes differ.