I hope someone can help. I'm learning Arcade and have been struggling with this one for a bit now.
ArcGIS Enterprise 11.3 Portal Dashboard app.
I have two polygon layers loaded into a Web Map, both are hosted feature services. Fuel Load and Compartments. They both have a LID field.
The web map is added to the dashboard. I want to create a Serial Chart in the Dashboard using a Data Expression, that joins these two layers on LID and returns fields from both that I can use.
I don't get any errors but once I click DONE, it says 'Unable to Execute Arcade Script.'
Any help will be appreciated.
You may need double equals sign at 'First(Filter(compLayer, "LID = @lid"))'. Try First(Filter(compLayer, "LID == @lid")) for comparison.
Also, while Arcade doesn't have robust error handling, you can try Console(x) or return x after any group of statements to see what they are. I prefer return so that the rest of the script isn't executed. Console doesn't appear to return anything if there's an error anywhere in the script.
The sql expression in the Filter function uses a single "=".
Your logic works using this testing data, so I would use @Ehei_Dogen's suggestion to use Console (use the Run button to see the results in the Arcade window) to see what's not working
// Replace with your actual Portal item IDs
var fuelItemID = "774019f31f8549c39b5c72f149bbe74e"; // states
var compItemID = "5f31109b46d541da86119bd4cf213848"; // zip codes
// Access both layers
var fuelLayer = FeatureSetByPortalItem(Portal("https://www.arcgis.com"), fuelItemID, 0, ["STATE_ABBR", "STATE_FIPS"],false);
console(fuelLayer)
var compLayer = FeatureSetByPortalItem(Portal("https://www.arcgis.com"), compItemID, 3, ["State", "POPULATION", "ZIP_CODE"],false);
console(compLayer)
// Array to store joined features
var joinedFeatures = [];
// Join loop
for (var fuel in fuelLayer) {
console(fuel["STATE_ABBR"])
var lid = fuel["STATE_ABBR"];
var match = First(Filter(compLayer, "State = @lid"));
if (!IsEmpty(match)) {
console(match["POPULATION"])
var attributes = {
COMPNO: fuel["STATE_FIPS"],
FUELLOADS: match["POPULATION"],
Plantation: match["ZIP_CODE"]
};
Push(joinedFeatures, {
attributes: attributes
});
}
}
// Define output FeatureSet schema
var fields = [
{ name: "COMPNO", type: "esriFieldTypeString" },
{ name: "FUELLOADS", type: "esriFieldTypeInteger" },
{ name: "Plantation", type: "esriFieldTypeString" },
{ name: "District", type: "esriFieldTypeString" },
{ name: "SuperDistrict", type: "esriFieldTypeString" }
];
// Return a proper FeatureSet
return FeatureSet({
fields: fields,
geometryType: "",
features: joinedFeatures
});