Arcade in Dashboards: Problem in Counting the Number of Records of a Feature Set

606
7
07-26-2021 11:43 PM
KarimKorbane
New Contributor II

 

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 DashboardArcade Expression in Dashboard

This screenshot shows the problem of how these two codes differ.

 

0 Kudos
7 Replies
JohannesLindner
Occasional Contributor III

It's pretty hard to guess at the problem when we don't have the code.

Can you please post the relevant section?

Expand the comment toolbar, select "Insert/Edit Code Sample" and choose Javascript as language.

JohannesLindner_0-1627372970703.png

 


Have a great day!
Johannes
0 Kudos
KarimKorbane
New Contributor II

I edited the post and added the codes.

Thank you. Have a great day!

0 Kudos
jcarlson
MVP Regular Contributor

I've tested both your code snippets, and I am unable to replicate this issue. Even on very large layers with many features, the Count function and the for loop return identical values.

Can you provide a screenshot of the behavior you're seeing? And if the layer in question is public, can you link to it?

- Josh Carlson
Kendall County GIS
0 Kudos
KarimKorbane
New Contributor II

Hello Josh.

First of all, I would like to thank you for your support.

I added the screenshot in the post, so please check it when you have some time. But regarding the layer, it is not public.

Thank you in advance and have a great day!

0 Kudos
jcarlson
MVP Regular Contributor

Interesting! I can't understand why it would differ. Is the layer in question public, by any chance? It would be nice if I could test this on the same data.

Alternately, can you test this process on some other layer and see if it still does the same thing?

- Josh Carlson
Kendall County GIS
0 Kudos
KenBuja
MVP Honored Contributor

I'm getting the same value for either version

count.png

0 Kudos
KarimKorbane
New Contributor II

Thank you for your support. But as you see in the post, the recently added screenshot shows the two codes and the difference in the retrieved values.

0 Kudos