Select to view content in your preferred language

Joining two layers in Dashboard

72
3
Friday
Labels (1)
KendallJames73
Emerging Contributor

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.

 

 

// Replace with your actual Portal item IDs
var fuelItemID = "b1234567897c44428d5756461df44455";  // Clan Fuel Lod
var compItemID = "e9876543215143799cc23fe3018jhr89";  // Clan Compartments

// Access both layers
var fuelLayer = FeatureSetByPortalItem(Portal("https://gis.my.org.com/portal"), fuelItemID, 0, ["LID", "COMPNO", "FUELLOADS"]);
var compLayer = FeatureSetByPortalItem(Portal("https://gis.my.org.com/portal"), compItemID, 0, ["LID", "Plantation", "District", "SuperDistrict"]);

// Array to store joined features
var joinedFeatures = [];

// Join loop
for (var fuel in fuelLayer) {
    var lid = fuel["LID"];
    var match = First(Filter(compLayer, "LID = @lid"));
   
    if (!IsEmpty(match)) {
        var attributes = {
            COMPNO: fuel["COMPNO"],
            FUELLOADS: fuel["FUELLOADS"],
            Plantation: match["Plantation"],
            District: match["District"],
            SuperDistrict: match["SuperDistrict"]
        };
       
        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
});
0 Kudos
3 Replies
Ehei_Dogen
Frequent Contributor

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.

0 Kudos
KenBuja
MVP Esteemed Contributor

The sql expression in the Filter function uses a single "=".

0 Kudos
KenBuja
MVP Esteemed Contributor

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
});

 

0 Kudos