Thank you for your answer @ChrisDunn1 !
Input of count is a feature set but it looks that the issue appears when it has no records. I use FeatureSetByName to get records from related table and for some objects there are no records. How can I add a check for null before the count statement? Tried to use IsEmpty function, but it returns 'False' when there are no records in my feature set.
Below you can find my code. As I wrote before - everything is working fine in Web Map i AGOL. When I try to use Field Maps, I get an error:
* for empty feature set the error refers to line with statement "var mycount = Count(utl_f)", so IsEmpty returns "false" for empty feature set
* for feature set with some objects, the Count function seems to be working, but error refers to line with the statement "var dismarray = Distinct(marray)". Are there also any special conditions for Distinct function to make it work in Field Maps?
var parsellnr = $feature.parsellid
var utl = FeatureSetByName($map, 'utløpsgrøft - tilstand')
var sql1 = "parsellid = '" + parsellnr + "' ";
var sql2 = " AND tilstand = '2' "
var sql = sql1 + sql2
var utl_f = Filter(utl, sql)
if (!IsEmpty(utl_f)){
var mycount = Count(utl_f)
}
var marrayix = 0
var marray = []
var antunik = 0
if (mycount>0) {
for (var c in utl_f){
var glid = c.utlopsgroft_ID
marray[marrayix]= glid
var dismarray = Distinct(marray)
++marrayix
}
var antunik = Count(dismarray)
}
return antunik
I really appreciate your help,
Aleksandra