Find soonest date from multiple fields in arcade (label) in Map Viewer

601
4
Jump to solution
05-15-2023 02:46 PM
Labels (1)
KevinMcCartney1
New Contributor II

We have Enterprise 10.9.1, working with Map Viewer (new). The requirement of my label expression is that it shows the soonest (approaching) date. Candidate values exist in 4 fields. Does arcade have the facility to select the minimum date?

In Python in Pro this was done with an array and min().

def FindLabel ( [DEADLINE_1], [DEADLINE_2], [DEADLINE_3], [DEADLINE_4] 😞
    
    dt1 = datetime.datetime.strptime([DEADLINE_1], '%m/%d/%Y')
    dt2 = datetime.datetime.strptime([DEADLINE_2], '%m/%d/%Y') if [DEADLINE_2] is not None else datetime.datetime.strptime('12/31/9999', '%m/%d/%Y')
    dt3 = datetime.datetime.strptime([DEADLINE_3], '%m/%d/%Y') if [DEADLINE_3] is not None else datetime.datetime.strptime('12/31/9999', '%m/%d/%Y')
    dt4 = datetime.datetime.strptime([DEADLINE_4], '%m/%d/%Y') if [DEADLINE_4] is not None else datetime.datetime.strptime('12/31/9999', '%m/%d/%Y')
 
    ar = [dt1, dt2, dt3, dt4]
    
    ret = min(ar).strftime('%m/%d/%Y')
    return ret
 
Thanks in advance!
Tags (1)
0 Kudos
1 Solution

Accepted Solutions
TanuHoque
Esri Regular Contributor

The workflow is a bit different when you have a portal vs standalone server. Please check this out.
https://pro.arcgis.com/en/pro-app/latest/help/sharing/overview/map-image-layer.htm

 

About Sort(), did the help link I provided earlier not help? 😞

View solution in original post

0 Kudos
4 Replies
TanuHoque
Esri Regular Contributor

@KevinMcCartney1 

 

Try the Sort() function to see if that helps.

https://developers.arcgis.com/arcade/function-reference/array_functions/#sort

 

That said, since you have an enterprise server, and your python script works in ArcGIS Pro labeling; you should be able to publish that as a map service (aka map image layer) and consume that as a map image layer in the Map Viewer. Since the drawing will happen on the server side, your python code will just work and give you map showing features labelled with the earliest date/time values.

0 Kudos
KevinMcCartney1
New Contributor II

Thanks. Looking into publishing a map service, even when logged into Portal as our administrator it still shows the server as connection type "User Connection." This page notes Publisher or Administrator Connection required. Publish a map service—ArcGIS Pro | Documentation

Any more pointers on the former option with Sort() would be much appreciated.

0 Kudos
TanuHoque
Esri Regular Contributor

The workflow is a bit different when you have a portal vs standalone server. Please check this out.
https://pro.arcgis.com/en/pro-app/latest/help/sharing/overview/map-image-layer.htm

 

About Sort(), did the help link I provided earlier not help? 😞

0 Kudos
KevinMcCartney1
New Contributor II

That workflow for sharing the map image to Portal did the trick. Thanks!