As the title says, I'm working on a dashboard element (list?) that returns the latest related comment to each unique project; return no recent comments if none are available.
The goal is to have a snapshot update for leadership to review all projects without as much interactivity.
I have tested a few code options, but I'm missing something... Can someone help me through the logic?
Dashboard has both the Projects layer and the 3 related tables (Comments/Funding/Spending) associated.
I've tried a few iterations, but this is the code I'm ATTEMPTING to use in the "Data Expressions" option within Dashboards. I'm not married to this solution as long as the functionality stays the same as initially requested.
// Portal reference and item
var portalRef = Portal("https://Omitted for Security.maps.arcgis.com");
var itemId = "Omitted for Security";
// Load layers
// Layer 0 = Projects, Table 1 = Comments
var projects = FeatureSetByPortalItem(
portalRef,
itemId,
0,
["globalid", "projname"]
);
var comments = FeatureSetByPortalItem(
portalRef,
itemId,
1,
["projectguid", "comments", "commentdt", "last_edited_user"]
);
var features = [];
for (var p in projects) {
var related = Filter(comments, "projectguid = @p.globalid");
if (Count(related) > 0) {
var latest = First(OrderBy(related, "commentdt DESC"));
Push(features, {
attributes: {
projname: p.projname,
comment: latest.comments,
comment_date: Text(latest.commentdt, "MM/DD/YYYY h:mm a"),
commenter: latest.last_edited_user
}
});
} else {
Push(features, {
attributes: {
projname: p.projname,
comment: "No recent comments for this project.",
comment_date: "",
commenter: ""
}
});
}
}
// Build schema and return FeatureSet
var schema2 = {
fields: [
{ name: "projname", type: "esriFieldTypeString" },
{ name: "comment", type: "esriFieldTypeString" },
{ name: "comment_date", type: "esriFieldTypeString" },
{ name: "commenter", type: "esriFieldTypeString" }
],
geometryType: "",
spatialReference: { wkid: 4326 },
features: features
};
return FeatureSet(schema2);
Error during run: "Test execution error: Expected "!=", "<=", "<>", ">", ">=", "AND", "OR", "||", [ \t\n\r], [*/], [+\-], [<-=], [A-Za-z0-9_], or end of input but "." found.. Verify test data."
Main Error: Unable to Execute Arcade Script.
The first error I have been able to avoid with certain code attempts, but the second main error under the list of Data Expressions I haven't been able to bypass.
I'm sure I'm missing something quite obvious, but any feedback is helpful!
Solved! Go to Solution.
The variable substitution sqlExpression in line 39 is not correct. You'd have to do something like this
var globalId = p.globalid
var related = Filter(comments, "projectguid = @globalId");
The variable substitution sqlExpression in line 39 is not correct. You'd have to do something like this
var globalId = p.globalid
var related = Filter(comments, "projectguid = @globalId");
Thank you, @KenBuja !
Your feedback is much appreciated. 😊