Hi,
I am trying write a data expression to create a featureset with fields from related tables to use in dashboard indicators & table. @jcarlson I followed your post here, but I'm getting an error: "Test execution error: Execution error - Cannot access value using a key of this type. Verify test data." Can you provide any insight into where I went wrong?
Or, is there a better way to achieve this? I really need some fields from ALL the related tables to create indicators in my dashboard and I'm struggling big time on how to execute that.
Background:
I'm accessing the Stands (2) layer and trying to pull data from the related Harvest Table (cut plan) (5). I really need fields from all the related tables, but I started with just one to see if I could figure it out.
{
"currentVersion": 10.81,
"cimVersion": "2.6.0",
"id": 2,
"name": "Stands",
"type": "Feature Layer",
"parentLayer": null,
"defaultVisibility": true,
"minScale": 100000,
"maxScale": 0,
"canScaleSymbols": false,
"geometryType": "esriGeometryPolygon",
"description": "",
"copyrightText": "",
"editFieldsInfo": {
"creationDateField": "created_date",
"creatorField": "created_user",
"editDateField": "last_edited_date",
"editorField": "last_edited_user"
},
"ownershipBasedAccessControlForFeatures": null,
"syncCanReturnChanges": true,
"relationships": [
{
"id": 2,
"name": "Silviculture",
"relatedTableId": 6,
"cardinality": "esriRelCardinalityOneToMany",
"role": "esriRelRoleOrigin",
"keyField": "GlobalID",
"composite": true
},
{
"id": 3,
"name": "Seedlings",
"relatedTableId": 7,
"cardinality": "esriRelCardinalityOneToOne",
"role": "esriRelRoleOrigin",
"keyField": "GlobalID",
"composite": true
},
{
"id": 4,
"name": "Cut Plan",
"relatedTableId": 5,
"cardinality": "esriRelCardinalityOneToOne",
"role": "esriRelRoleOrigin",
"keyField": "GlobalID",
"composite": true
},
{
"id": 5,
"name": "Inventory",
"relatedTableId": 4,
"cardinality": "esriRelCardinalityOneToOne",
"role": "esriRelRoleOrigin",
"keyField": "GlobalID",
"composite": true
},
{
"id": 1,
"name": "Company Tracts",
"relatedTableId": 1,
"cardinality": "esriRelCardinalityOneToMany",
"role": "esriRelRoleDestination",
"keyField": "TractGUID",
"composite": true
// Set portal and layers
var p = 'https://gbp-frd.maps.arcgis.com'
var stfs = FeatureSetByPortalItem(Portal(p), 'e6ae2c4345a54bb29f789c2cde47bda2', 2);
Console(Count(stfs))
// Empty feature array and feat object to populate output
var features = [];
// Iterate over features in main layer
for (var f in stfs){
// grab related records for feature
var rel = FeatureSetByRelationshipName(f, "Cut Plan")
Console(Count(rel))
//iterate over related records
for (var r in rel){
//create feature dict
var feat = {
'attributes': {
'StandID_s' : f['StandID'],
'GlobalID_s' : f['GlobalID'],
'Age_s' : f['Age'],
'Acres_s' : f['Acres'],
'ConvAc_s' : f['Conv_Ac'],
'District_s' : f['District'],
'TractID_s' : f['TractID'],
'Operability' : f['Operability'],
'FirstThinPlanned': rel['T1P'],
'FirstThinActual' : rel['T1A'],
'SecondThinPlanned' : rel['T2P'],
'SecondThinActual' : rel['T2A'],
'ThirdThinPlanned' : rel['T3P'],
'ThirdThinActual' : rel['T3A'],
'PlannedHarvest' : rel['CCP'],
'ActualHarvest' : rel['CCA'],
'StandGUID_h' : rel['StandGUID'],
'StandID_h' : rel['StandID']
}
};
//push to array
Push(features, feat);
};
};
//create featureset dict, supply features array
var fs_dict = {
'fields': [
{'name': 'StandID', 'type': 'esriFieldTypeString'},
{'name': 'GlobalID', 'type': 'esriFieldTypeString'},
{'name': 'Age_s', 'type': 'esriFieldTypeInteger'},
{'name': 'Acres_s', 'type': 'esriFieldTypeDouble'},
{'name': 'Conv_AC_s', 'type': 'esriFieldTypeDouble'},
{'name': 'District_s', 'type': 'esriFieldTypeString'},
{'name': 'TractID_s', 'type': 'esriFieldTypeInteger'},
{'name': 'Operability', 'type': 'esriFieldTypeString'},
{'name': 'FirstThinPlanned', 'type': 'esriFieldTypeInteger'},
{'name': 'FirstThinActual', 'type': 'esriFieldTypeInteger'},
{'name': 'SecondThinPlanned', 'type': 'esriFieldTypeInteger'},
{'name': 'SecondThinActual', 'type': 'esriFieldTypeInteger'},
{'name': 'ThirdThinPlanned', 'type': 'esriFieldTypeInteger'},
{'name': 'ThirdThinActual', 'type': 'esriFieldTypeInteger'},
{'name': 'PlannedHarvest', 'type': 'esriFieldTypeInteger'},
{'name': 'ActualHarvest', 'type': 'esriFieldTypeInteger'},
{'name': 'StandGUID_h', 'type': 'esriFieldTypeString'},
{'name': 'StandID_h', 'type': 'esriFieldTypeString'},
],
'geometryType': '',
'features': features
};
return FeatureSet(Text(fs_dict))
My Console shows:
Thank you!!