Arcade "Count" issues

285
9
3 weeks ago
BenSmith93
New Contributor II

I'm using the below code, attempting to filter a related table for inspections to show a message in the pop-up

var gid = $feature.globalid
console(gid)
var signcount = filter(FeatureSetByName($map,'Sign_Information', ['*']),'parentglobalid = gid')
console(signcount)
var x = typeof(signcount)
console(x)
var sign = count(signcount)
console("sign = "+sign)

var p = ""
when(sign > 1, p = "There are "+sign+" sign surveys on this asset",
sign == 1, p = "There is 1 sign survey on this asset",
p = "There are no sign surveys recorded for this asset")
return p

This just fails and errors in the expression builder.

Further interrogation in Pro gives

BenSmith93_1-1622548234258.png

 

I have consoled out the type of the signcount to rule out issues there.

What's the inevitably very obvious thing I'm missing?

Thanks

0 Kudos
9 Replies
JayantaPoddar
MVP Esteemed Contributor

Filter()

TypeOf()

Count()

Console()

When()

*in Proper Case. Does it work?

0 Kudos
BenSmith93
New Contributor II
Arcade is supposed to remove the case dependency, but also, no unfortunately not.
0 Kudos
JayantaPoddar
MVP Esteemed Contributor

Could you add the Boolean (includeGeometry?) to FeatureSetByName() function?

I understand it's optional. But still want to tick off that option as the probable cause of the problem.

 

0 Kudos
BenSmith93
New Contributor II
Unfortunately that doesn't work either.

As the error says, it's getting past the FeatureSetByName (I also tried ID) before the error, it's specifically the count that fails.

There is an issue with the feature set getting created by the filter. I've just tried the script out without the filter and it works fine

0 Kudos
BenSmith93
New Contributor II

See below, but looks like I've sorted one problem at least.

The filter wasn't working properly as I hadn't done the SQL query correctly, needed an "@" before "gid" to set it as an arcade variable.

Still not working in the actual pop-up, but it is working in the expression builder.

0 Kudos
KenBuja
MVP Honored Contributor

Your filter clause is failing due to incorrect syntax. "gid" is a string variable, not the actual value for parentglobalid. Use this syntax

var signcount = filter(FeatureSetByName($map,'Sign_Information', ['*']),"parentglobalid = '" + gid + "'");

 

0 Kudos
BenSmith93
New Contributor II

It's not even as complicated as that.
var signcount = filter(FeatureSetByName($map,'Sign_Information', ['*']),'parentglobalid = @gid') to declare it as an arcade variable

0 Kudos
KenBuja
MVP Honored Contributor

That's a more concise syntax I didn't know about. Is your script working now?

0 Kudos
BenSmith93
New Contributor II
Nor did I, annoyingly it wasn't even hidden in the depths of some obscure guide, it's on the guide for anything that has an SQL string query in the function reference.

To a degree, it's working in the expressions builder but not in the actual pop-ups.
0 Kudos