Select to view content in your preferred language

Arcade Code Question for Popup. Compare two hosted services

415
2
Jump to solution
11-18-2022 06:58 AM
ArmstKP
Frequent Contributor

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

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

You're comparing firsteventhistorySorted and firstplowhistorySorted. These are features from different feature sets, so they will probably never be the same. Instead, you watn to compare the eventstart attribute of both features:

var go = IIF(firsteventhistorySorted.eventstart == firstplowhistorySorted.eventstart, popupString, "")

 

If there is no guarantee that eventstart will be exactly the same in both feature sets, you will probably want to format these date values before comparing:

var date1 = Text(firsteventhistorySorted.eventstart, "Y-MM-DD HH:mm")
var date2 = Text(firstplowhistorySorted.eventstart, "Y-MM-DD HH:mm")
var go = IIF(date1 == date2, popupString, "")

Have a great day!
Johannes

View solution in original post

0 Kudos
2 Replies
JohannesLindner
MVP Frequent Contributor

You're comparing firsteventhistorySorted and firstplowhistorySorted. These are features from different feature sets, so they will probably never be the same. Instead, you watn to compare the eventstart attribute of both features:

var go = IIF(firsteventhistorySorted.eventstart == firstplowhistorySorted.eventstart, popupString, "")

 

If there is no guarantee that eventstart will be exactly the same in both feature sets, you will probably want to format these date values before comparing:

var date1 = Text(firsteventhistorySorted.eventstart, "Y-MM-DD HH:mm")
var date2 = Text(firstplowhistorySorted.eventstart, "Y-MM-DD HH:mm")
var go = IIF(date1 == date2, popupString, "")

Have a great day!
Johannes
0 Kudos
ArmstKP
Frequent Contributor

@JohannesLindner Thank you so much, this was the ticket!!

0 Kudos