Select to view content in your preferred language

Empty featureset in arcade in dashboard

1869
4
06-02-2021 04:21 AM
mody_buchbinder
Frequent Contributor

I am trying to create a pie chart in dashboard using arcade.

I am query a layer by a list of values and create some values for the pie.

The basic lines is

 var sql = "GlobalID = '" + globalId + "'";
var featureLocation = Filter(fs_location, sql);

where the golbalID change in a loop.

It all works fine when the feature set contain values. The problem is when it return nothing.

I tried "isEmpty(featureLocation)" but it return an error.

I tried some simple loop:

var c = 0
for(var s in featureLocation)
{
c = c + 1
}

it return an error too.

Unlike many of the examples I do not have $feature here.

Any good way to understand nothing is coming back and does not get an error?

 

Thanks

 

0 Kudos
4 Replies
JohannesLindner
MVP Frequent Contributor

If you expand the tollbar in the comment box, you can insert code samples:

JohannesLindner_0-1622633201561.png

 

Try this:

if(Count(featureLocation) == 0) {
  // noting found, return null
  return null
}

Have a great day!
Johannes
KenBuja
MVP Esteemed Contributor

This appears to be a problem when filtering by GlobalID. If you put in a filter clause on a field that returns no values (like "var filter = Filter(fs, 'objectid = 0')"), the filter count is 0.

 

0 Kudos
mody_buchbinder
Frequent Contributor

Hi

I found out that when the globalID is empty you get an error.

Still the expression GlobalID = '' is valid but any reference to the featureSet it returns (including Count) return an error.

0 Kudos
JohannesLindner
MVP Frequent Contributor

Have you tried checking for null?

if(featureLocation == null || Count(featureLocation) == 0) {
  // noting found, return null
  return null
}

Have a great day!
Johannes
0 Kudos