Arcade Expression FeatureSet By Association

851
2
Jump to solution
02-06-2023 12:03 AM
Labels (3)
Mohamed_Gamal
New Contributor II

i am trying to get all content features and put their GlobalID inside new array and use this array later to filter the table or the feature class containing this features.

 

var contentRows  = FeatureSetByAssociation($feature, "content");
var globalIds = [];
var i = 0;
for (var v in contentRows) {
  globalIds[i++] =v.globalId
}
var asset_Array=[27,26]
var deviceClass = FeatureSetByName($datastore, "CommunicationsJunctionObject");
var devicesRows = Filter(deviceClass, "globalid in @globalIds");
return{'errorMessage':count(devicesRows)}

 

Error Message

Mohamed_Gamal_0-1675670580784.png

 

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

I believe ArcGIS uses default values when it verifies Arcade expressions. That means that it often doesn't find anything with functions like FeaturesetByRelationshipName() and Filter() adn returns empty featuresets.

In your case, it returned an empty fs with FeaturesetByAssociation(), so your globalIDs array is empty, which leads to your query being "GlobalID IN ()" which is invalid.

Try guarding against empty featuresets:

var contentRows  = FeatureSetByAssociation($feature, "content");
var globalIds = [];
var i = 0;
for (var v in contentRows) {
  globalIds[i++] =v.globalId
}
var deviceCount = 0  // set a defaul value
if(i > 0) {  // only enter this block if contentRows is not empty
    var asset_Array=[27,26]
    var deviceClass = FeatureSetByName($datastore, "CommunicationsJunctionObject");
    var devicesRows = Filter(deviceClass, "globalid in @globalIds");
    deviceCount = Count(deviceRows)  // overwrite the default value
}
return{'errorMessage':deviceCount}

Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Frequent Contributor

I believe ArcGIS uses default values when it verifies Arcade expressions. That means that it often doesn't find anything with functions like FeaturesetByRelationshipName() and Filter() adn returns empty featuresets.

In your case, it returned an empty fs with FeaturesetByAssociation(), so your globalIDs array is empty, which leads to your query being "GlobalID IN ()" which is invalid.

Try guarding against empty featuresets:

var contentRows  = FeatureSetByAssociation($feature, "content");
var globalIds = [];
var i = 0;
for (var v in contentRows) {
  globalIds[i++] =v.globalId
}
var deviceCount = 0  // set a defaul value
if(i > 0) {  // only enter this block if contentRows is not empty
    var asset_Array=[27,26]
    var deviceClass = FeatureSetByName($datastore, "CommunicationsJunctionObject");
    var devicesRows = Filter(deviceClass, "globalid in @globalIds");
    deviceCount = Count(deviceRows)  // overwrite the default value
}
return{'errorMessage':deviceCount}

Have a great day!
Johannes
Mohamed_Gamal
New Contributor II

It works just fine, Thanks

0 Kudos