Hello, I'm attempting to create an arcade script that combines three layers (point, line, and polygon) with the same schema and then displaying that in a serial chart or pie chart. When I attempt to run the expression below the dashboard expression editor has this as the output. Any help would be greatly apricated! I've been staring at this for hours...
Thanks!
var p = Portal("https://maps.xyzxyzxy.com/portal/");
var point_field = FeatureSetByPortalItem(p,***itemid***,0,["Cat28Code2025","Notes2025","Ocondition2025","RBU"],false);
var polyline_field = FeatureSetByPortalItem(p,"***itemid***",0,["Cat28Code2025","Notes2025","Ocondition2025","RBU"],false);
var polygon_field = FeatureSetByPortalItem(p,"***itemid***",0,["Cat28Code2025","Notes2025","Ocondition2025","RBU"],false);
var combinedDict = {
fields:[
{name : "CatCode",type : "esriFieldTypeSmallInteger"},
{name : "Notes",type : "esriFieldTypeString"},
{name : "Condition",type : "esriFieldTypeDouble"},
{name : "BusinessUnit",type : "esriFieldTypeString"},
{name : "Source", type : "esriFieldTypeString"},
],
'geometryType':"",
'features':[], //create empty array for features
};
var i = 0;
//Loop through each FeatureSet and populate feature array
for (var m in point_field){
combinedDict.features[i] = {
attributes: {
CatCode : m["Cat28Code2025"],
Notes : m["Notes2025"],
Condition : m["Ocondition2025"],
BusinessUnit : m["RBU"],
Source : "Point"
},
};
i++;
}
for (var m in polyline_field){
combinedDict.features[i] = {
attributes: {
CatCode : m["Cat28Code2025"],
Notes : m["Notes2025"],
Condition : m["Ocondition2025"],
Source : "Polyline"
},
};
i++;
}
for (var m in polygon_field){
combinedDict.features[i] = {
attributes: {
CatCode : m["Cat28Code2025"],
Notes : m["Notes2025"],
Condition : m["Ocondition2025"],
Source : "Polygon"
},
};
i++;
}
// Return dictionary cast as a feature set
return FeatureSet(Text(combinedDict));
Solved! Go to Solution.
Your issue is that you have this in your code trying to populate an array but it is set to populate a dictionary.
combinedDict.features[i]
So you want to change it to look like the example below.
for (var m in polygon_field){
var A = {
attributes: {
CatCode : m["Cat28Code2025"],
Notes : m["Notes2025"],
Condition : m["Ocondition2025"],
Source : "Polygon"
}
}
Push( combinedDict.features , A )
}
I am also throwing this example in here to showcase a simpler manner to write the same code.
function CreateDictValues( InArray , InFeature , Fields , Geometry ){
for( var row in InFeature ){
var Values = iif( !IsEmpty( Geometry ) , { Source : Geometry } , {} )
var Valid = False
for( var field in row ){
if( HasKey( Fields , field ) ){
field = Fields[ field ]
Values[ field ] = i[ field ]
Valid = True
}
}
if( Valid ){ Push( InArray , { attributes: Values } ) }
}
return InArray
}
//Loop through each FeatureSet and populate feature array
var PopValues = []
var F = {"Cat28Code2025":'CatCode',"Notes2025":'Notes',"Ocondition2025":"Condition","RBU":"BusinessUnit"}
CreateDictValues( PopValues , point_field , F , "Point" )
CreateDictValues( PopValues , polyline_field , F , "Point" )
CreateDictValues( PopValues , polygon_field , F , "Point" )
// Return dictionary cast as a feature set
var combinedDict = {
fields:[
{name : "CatCode",type : "esriFieldTypeSmallInteger"},
{name : "Notes",type : "esriFieldTypeString"},
{name : "Condition",type : "esriFieldTypeDouble"},
{name : "BusinessUnit",type : "esriFieldTypeString"},
{name : "Source", type : "esriFieldTypeString"},
],
'geometryType':"",
'features':PopValues ,
}
return FeatureSet(Text(combinedDict))
Your issue is that you have this in your code trying to populate an array but it is set to populate a dictionary.
combinedDict.features[i]
So you want to change it to look like the example below.
for (var m in polygon_field){
var A = {
attributes: {
CatCode : m["Cat28Code2025"],
Notes : m["Notes2025"],
Condition : m["Ocondition2025"],
Source : "Polygon"
}
}
Push( combinedDict.features , A )
}
I am also throwing this example in here to showcase a simpler manner to write the same code.
function CreateDictValues( InArray , InFeature , Fields , Geometry ){
for( var row in InFeature ){
var Values = iif( !IsEmpty( Geometry ) , { Source : Geometry } , {} )
var Valid = False
for( var field in row ){
if( HasKey( Fields , field ) ){
field = Fields[ field ]
Values[ field ] = i[ field ]
Valid = True
}
}
if( Valid ){ Push( InArray , { attributes: Values } ) }
}
return InArray
}
//Loop through each FeatureSet and populate feature array
var PopValues = []
var F = {"Cat28Code2025":'CatCode',"Notes2025":'Notes',"Ocondition2025":"Condition","RBU":"BusinessUnit"}
CreateDictValues( PopValues , point_field , F , "Point" )
CreateDictValues( PopValues , polyline_field , F , "Point" )
CreateDictValues( PopValues , polygon_field , F , "Point" )
// Return dictionary cast as a feature set
var combinedDict = {
fields:[
{name : "CatCode",type : "esriFieldTypeSmallInteger"},
{name : "Notes",type : "esriFieldTypeString"},
{name : "Condition",type : "esriFieldTypeDouble"},
{name : "BusinessUnit",type : "esriFieldTypeString"},
{name : "Source", type : "esriFieldTypeString"},
],
'geometryType':"",
'features':PopValues ,
}
return FeatureSet(Text(combinedDict))
I was about to get both my expression and the one above to work. My problem was in the FeatureSetByPortalItem. I had the incorrect layerid. The zero needed to be 1