Return date from a related table in a pop-up in Field Maps

391
4
12-29-2020 09:10 AM
Zank_Benjamin_P
New Contributor III

I have a feature layer that has points representing range improvement feature and a related table (1:M) that stores inspection records of those range improvements. I would like to return the last inspection date recorded in the inspection table for those features as an attribute in the pop-up of the range improvement point in the Field Maps app. 

I am able to do this successfully in a web map using the Arcade expression below. However when I click on features live in Field Maps I am only half successful. For features without inspection records the expression will return "No inspection records found" to the pop-up, but for features with related inspection records I se only a  "-" rather than the date I see when I look at the pop-up in a web map. 


var sql = "range_imp_guid = '"+$feature.GlobalID+"'";

var tbl = Filter(FeatureSetByName($map,"Point Inspection"), sql);
var cnt = Count(tbl);

var lastinsp = "";
if (cnt > 0) {
var tbl_ord = OrderBy(tbl, 'last_insp_date DES');
var info = First(tbl_ord);
lastinsp = Text((info.last_insp_date), "MM-DD-Y");
}
else {
lastinsp = "No inspection records found"
}
return lastinsp;

4 Replies
DavidPike
MVP Frequent Contributor

Hi Ben, my JS and SQL is pretty awful, but one thing I do see is 'DES' rather than 'DESC' In the orderBy clause.  You also might have some luck investigating what First(tbl_ord) is returning - outside of any logic. 

 

var sql = "range_imp_guid = '"+$feature.GlobalID+"'";

var tbl = Filter(FeatureSetByName($map,"Point Inspection"), sql);
var cnt = Count(tbl);

var lastinsp = "";
if (cnt > 0) {
  var tbl_ord = OrderBy(tbl, 'last_insp_date DESC');
  var info = First(tbl_ord);
  lastinsp = Text(info.last_insp_date, "MM-DD-Y");
  return lastinsp;
}  else {
  lastinsp = "No inspection records found"
  return lastinsp;
}
0 Kudos
Zank_Benjamin_P
New Contributor III

Hi David,

Thank you for the suggestion. I replaced the expression you suggested above with the one I had written and observed the same behavior. The Last Inspection Date is successfully returned on features that have inspection records and the "No inspection" text is returned on features that do not, but in the Field Maps app only the "No inspection" text is returned in the pop-up. 

0 Kudos
ArmstKP
Occasional Contributor

I have gotten the expression to function and return values and "No Inspection" in Field Maps, just tested it....

Zank_Benjamin_P
New Contributor III

I can also get this to work in the Field Maps app when I am connected live to the service, but when I take the data offline if seems to break and only show "No Inspection" once again. 

0 Kudos