I have a dashboard set up to show my Survey123 data and am using an Arcade expression to join tables from repeats to the base layer to attach the date information to filter all the tables in my dashboard.
I had this expression working properly but it was very poorly optimized and I was getting consistent complaints about that fact, I moved to update the code from another post I found here on the Esri Community and the speed has dramatically improved. However I am finding occasionally rows are missing from the table showing the repeat information and I am not sure why.
My code is here:
function Memorize(fs) {
var temp_dict = {
fields: Schema(fs)['fields'],
geometryType: '',
features: []
}
for (var f in fs) {
var attrs = {}
for (var attr in f) {
attrs[attr] = Iif(TypeOf(f[attr]) == 'Date', Number(f[attr]), f[attr])
}
Push(
temp_dict['features'],
{attributes: attrs}
)
}
return FeatureSet(Text(temp_dict))
}
var portal = Portal("https://www.arcgis.com/");
var polyfs = Memorize(FeatureSetByPortalItem(
portal,
"(valid itemID is pasted here)",
0,
["*"],
false
)
);
var tablefs = Memorize(FeatureSetByPortalItem(
portal,
"(valid itemID is pasted here)",
2,
["*"],
false
)
);
var joinedDict = {
fields: [
{ name: "FeatureID", type: "esriFieldTypeString" },
{ name: "Date", type: "esriFieldTypeDate" },
{ name: "Location", type: "esriFieldTypeString" },
{ name: "Vehicle", type: "esriFieldTypeString" },
{ name: "VehHours", type: "esriFieldTypeDouble" },
{ name: "VehAct", type: "esriFieldTypeString" },
],
'geometryType': '',
features:[]
};
// Populate Feature Array
for (var v in tablefs) {
var tableID = v["parentglobalid"]
for (var p in Filter(polyfs, "globalid =@tableID")){
Push(
joinedDict['features'],
{
attributes: {
FeatureID: tableID,
Date: Number(p["WO_StartDate"]),
Location: p["Location"],
Vehicle: v["Vehicle"],
VehHours: v["veh_time"],
VehAct: v["veh_act"],
}
}
)
}
}
// Return dictionary cast as a feature set
return FeatureSet(Text(joinedDict));