Select to view content in your preferred language

Data expression to join two layers to be used in dashboard chart

495
2
Jump to solution
06-06-2024 07:52 AM
dwold
by
Frequent Contributor

I am trying to write a data expression to return fields from 2 different data layers. My data expression looks like this:

var portal = Portal('https://piercecowa.maps.arcgis.com');

var thira = FeatureSetByPortalItem(portal,'aff5dd7c9615404cac256ec6dc627e10', ['*'],false)
var poete = FeatureSetByPortalItem(portal,'aff5dd7c9615404cac256ec6dc627e10', 1, ['*'],false)


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


for (var x in poete){

  var ParentGlobalID = x["parentglobalid"]
  var poete_area = x['poete_area']

  var Name;
  var UASI_Jurisdiction;
  var Community;
  var Core_Capability;
  var Target

  for (var y in thira ){
    if (y["globalid"] == ParentGlobalID){
      Name = y['Name']
      UASI_Jurisdiction = y['Jurisdiction']
      Community = y['Sub_Jurisdiction:']
      Core_Capability = y['core_capability']
      Target = y['target']
      break
    }
  }

  feat = {
    attributes: {
        Name: Name,
        UASI_Jurisdiction: UASI_Jurisdiction,
        Community: Community,
        Core_Capability: Core_Capability,
        Target: Target,
        poete_area: poete_area
    }
  }

  Push(features, feat)
}

var joinedDict = {
    fields: [
        { name: "ParentGlobalID", type: "esriFieldTypeGUID" },	
        { name: "poete_area", type: "esriFieldTypeString" },
        { name: "Name", type: "esriFieldTypeString" },
        { name: "UASI_Jurisdiction", type: "esriFieldTypeString" },
        { name: "Community", type: "esriFieldTypeString" },
        { name: "Core_Capability", type: "esriFieldTypeString" },
        { name: "Target", type: "esriFieldTypeString" },
    ],
    'geometryType': '',
    'features':features
};

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

poete_area data:

dwold_0-1717684998588.png

dwold_3-1717685477633.png

 

thira data:

dwold_1-1717685392392.pngdwold_2-1717685424501.png

dwold_4-1717685523239.png

 

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

You're missing the layerid in line 3

View solution in original post

2 Replies
KenBuja
MVP Esteemed Contributor

You're missing the layerid in line 3

dwold
by
Frequent Contributor

@KenBuja thanks!!

0 Kudos