Hi All,
I have a simple test map for trying out a few things. In this map I have a point feature and a related table. The point features will remain static, and each month field users will submit a new record to the related table as an inspection documentation process. I want to reference the current and last records in the pop-up for the parent point features. I already have a solid bit of code that gets the feature set, and filters based on the related fields. I then am using "First" and "OrderBy" to select the most recent related record, and am able to get the pop-up to show the fields I am looking for, but I cannot get the second to last record. I want this to be a rolling pop-up that with each added related record, it references the first and second most recent related records, and pull 2 fields from each record. I assumed "Second" and "OrderBy" would get me what I am after, but "Second" refers to time functions and not what I am after. Can anybody point me in the direction I'm looking for here? Code is inserted below. The parent feature is "Odorizer" and the child table is "Odorizer Inspection" The key field in Odorizer is the GlobalID and the key field in Odorizer Inspection is ODGlobal. I have them ordered by the field "InspectionDate" currently.
Thanks,
Damon
var global = $feature.GlobalID; // change the name of the field
var tblReads = FeatureSetByName($map, "Odorizer Inspection");
var sql = "ODGlobal = '" + global + "'"; // if field is text
var relReads = Filter(tblReads, sql);
var cnt = Count(relReads);
Console(cnt);
var result = "";
if (cnt > 0) {
result = "Last Read" + TextFormatting.NewLine;
var currentRead = First(OrderBy(relReads, 'OBJECTID'));
var currentRate = currentRead.CurrentInjectedL / currentRead.MeterReading;
result += "Current Odorant: " + currentRead.CurrentInjectedL + TextFormatting.NewLine;
result += "Current Gas: " + currentRead.MeterReading + TextFormatting.NewLine;
result += "Rate:" + currentRate;
return result;
} else {
result = "There are no reads yet";
}
return result;