Arcade - Join features attribute

455
3
08-29-2022 11:11 PM
Labels (1)
junaidjawaid
New Contributor III

Hi, I am trying to combine the attributes from two layers hosted in the ArcGIS server with following code in Arcade Data Expression . In both layers, the fields on which the join will based is of the same data type i.e. String. The expression is returning following error.

 

// Create empty features array and feat object
var features = [];
var feat;

for (var t in CS) {
var tableID = t["ID"]
for (var p in Filter(DTS, "FEEDERID = "+tableID)){
feat = {
attributes: {
Name: t["Name"],
}
}



Push(features, feat)
}
}


var joinedDict = {
fields: [
{ name: "Name", type: "esriFieldTypeString" },
],
'geometryType': '',
'features':features
};

// Return dictionary cast as a feature set
return FeatureSet(joinedDict);

 

Error Snapshot : 

 

junaidjawaid_0-1661839838376.png

 

Tags (2)
0 Kudos
3 Replies
JohannesLindner
MVP Frequent Contributor

The field type is string, so your SQL filter expression should look for string values. You have to enclose your tableID with single quotes:

for (var p in Filter(DTS, "FEEDERID = '"+tableID+"'")){
//...
}

 

Better yet, let Arcade handle the types:

for (var p in Filter(DTS, "FEEDERID = @tableID")){
//...
}

Have a great day!
Johannes
0 Kudos
junaidjawaid
New Contributor III

Hi Johannes,

Thanks for your suggestion, now a different error is shown as below:

 

Execution Error:Invalid Parameter

0 Kudos
JohannesLindner
MVP Frequent Contributor

FeatureSet() needs a json string, not a dictionary. Try this:

return FeatureSet(Text(joinedDict));

Have a great day!
Johannes
0 Kudos