Select to view content in your preferred language

Can you use a Data Expression to reference a layer filtered by a Category Selector?

518
1
03-09-2023 10:39 AM
ZachLansford_HD
New Contributor II

Is it possible to set up a Data Expression to reference a layer within the dashboard that is being filter by a Category Selector?

I have a dataset that is comprised of a point layer and a related table. The point layer represents a summary of a days work in the field with a particular piece of equipment - ex metal detector, backhoe, etc covering x area in y hours. There is a one to many relationship set up with a table that contains specifics about what possible items are being found in the field, with several fields categorizing the items as well as number of items found.

I have set up a dashboard with some Category Selectors that apply to the spatial point layer. Is there a way to set up a Data Expression where the filtered spatial layer also filters the indicators that are referencing the related table?

0 Kudos
1 Reply
ZachLansford_HD
New Contributor II

I believe I have found a solution, although it is a little cumbersome. I constructed a Data Expression that joins the fields I am filtering by (equipment name, region, operator) in the point layer to the relevant data I need from the related table. Now I can use the source and target field functions in the Selector since I have matching fields between the two datasets.

 

var portal = Portal("https://www.arcgis.com/");
var pointFS = FeatureSetByPortalItem(
  portal,
  "portalID",
  0,
  ["tech","operator","country","record_date"],
  False
);

var tablefs = FeatureSetByPortalItem(
  portal,
  "portalID",
  1,
  ["*"],
  False
);

var features = [];
var feat;

for (var t in tablefs){
  var TableID = t["op_record_id"]
  for (var p in Filter(pointFS, "op_record_id ="+TableID)){
    feat = {
      attributes: {
        FeatureID: TableID,
        tech: p["tech"],
        operator: p["operator"],
        country: p["country"],
        device_group: t["device_group"],
        device_category: t["device_category"],
        quantity: t["quantity"],
      }
    }

    Push(features, feat)
  }
}

var joinedDict = {
  fields: [
    {name: "FeatureID", type: "esriFieldTypeString"},
    {name: "tech", type: "esriFieldTypeString"},
    {name: "operator", type: "esriFieldTypeString"},
    {name: "country", type: "esriFieldTypeString"},
    {name: "device_group", type: "esriFieldTypeString"},
    {name: "device_category", type: "esriFieldTypeString"},
    {name: "quantity", type: "esriFieldTypeInteger"},
  ],
  'geometryType':'',
  'features':features
};

return FeatureSet(Text(joinedDict));
0 Kudos