I have my code below, but it doesn't seem to be functioning - it never returns any values. Any thoughts or issue with the code?
I have a hosted feature layer (plowhistory), that adds a segment each time a snow plow travels over it - it may be the same segment as well. The plowhistory has a field with the snow eventstart date. I also have a snow event table (eventhistory) and in one field is the eventstart date. After sorting both plowhistory and eventhistory by descending and grabbing the first record will give me the latest event eventstart date. If those two equal the same eventstart date, then create the popup detailed below.
var plowhistory = Intersects(FeatureSetByPortalItem(Portal('https://www.arcgis.com'),"eb5bff771453481fad221128d16d5a25",0), $feature);
var eventhistory = FeatureSetByPortalItem(Portal('https://www.arcgis.com'),"0bb7f78fd9244694b7bbf1dcf9480303",1, ['eventstart'],false);
var plowhistorySorted = OrderBy(plowhistory, 'eventstart DSC')
var eventhistorySorted = OrderBy(eventhistory, 'eventstart DSC')
var firstplowhistorySorted = First(plowhistorySorted)
var firsteventhistorySorted = First(eventhistorySorted)
var popupString = "";
for (var myfeature in plowhistorySorted){
popupString += text(myfeature.lastserviced, 'MMM DD Y, hh:mm A') +
TextFormatting.NewLine + TextFormatting.NewLine
}
var go = IIF(firsteventhistorySorted == firstplowhistorySorted, popupString, "")
return go