<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Arcade how to copy date field intersection in ArcGIS Field Maps Questions</title>
    <link>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-how-to-copy-date-field-intersection/m-p/1495863#M8921</link>
    <description>&lt;P&gt;Hi, I am following this blog to try and build my smart form to replicate the old Smart Editor Widget in Web App builder:&amp;nbsp;&lt;A href="https://www.esri.com/arcgis-blog/products/arcgis-online/mapping/from-the-smart-editor-to-smart-forms/" target="_blank"&gt;From the Smart Editor to Smart Forms (esri.com)&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I have used the below code to copy attribute data from an intersection layer when creating a new feature to replicate the smart editor copy, however I cannot get the code to work to copy across a Date and time field. Does anyone have any ideas how i go about this using Arcade calculated expression form in field maps designer please?&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// Get the bus stops layer
// To customize, replace the layer name below
var busStops = FeatureSetByName($map,"RTD Active Bus Stops")
// Buffer the current location and intersect with the bus stops
var bufferedLocation = Buffer($feature, 1000, 'feet')
var candidateStops = Intersects(busStops, bufferedLocation)
// Calculate the distance between the bus stops and the current location
// Store the feature and distance as a dictionary and push it into an array
var featuresWithDistances = []
for (var f in candidateStops) {
    Push(featuresWithDistances, 
        {
            'distance': Distance($feature, f, 'feet'),
            'feature': f
        }
    )
}
// Sort the candidate bus stops by distance using a custom function
function sortByDistance(a, b) {
    return a['distance'] - b['distance']
}
var sorted = Sort(featuresWithDistances, sortByDistance)
// Get the closest bus stop
var closestFeatureWithDistance = First(sorted)
// If there was no bus stop, return null
if (IsEmpty(closestFeatureWithDistance)) { return null }
// Return the bus stop name attribute value
// To customize, replace the field name "STOPNAME" below
return `${closestFeatureWithDistance['feature']['STOPNAME']}`&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 21 Jun 2024 13:11:15 GMT</pubDate>
    <dc:creator>cat206</dc:creator>
    <dc:date>2024-06-21T13:11:15Z</dc:date>
    <item>
      <title>Arcade how to copy date field intersection</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-how-to-copy-date-field-intersection/m-p/1495863#M8921</link>
      <description>&lt;P&gt;Hi, I am following this blog to try and build my smart form to replicate the old Smart Editor Widget in Web App builder:&amp;nbsp;&lt;A href="https://www.esri.com/arcgis-blog/products/arcgis-online/mapping/from-the-smart-editor-to-smart-forms/" target="_blank"&gt;From the Smart Editor to Smart Forms (esri.com)&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I have used the below code to copy attribute data from an intersection layer when creating a new feature to replicate the smart editor copy, however I cannot get the code to work to copy across a Date and time field. Does anyone have any ideas how i go about this using Arcade calculated expression form in field maps designer please?&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// Get the bus stops layer
// To customize, replace the layer name below
var busStops = FeatureSetByName($map,"RTD Active Bus Stops")
// Buffer the current location and intersect with the bus stops
var bufferedLocation = Buffer($feature, 1000, 'feet')
var candidateStops = Intersects(busStops, bufferedLocation)
// Calculate the distance between the bus stops and the current location
// Store the feature and distance as a dictionary and push it into an array
var featuresWithDistances = []
for (var f in candidateStops) {
    Push(featuresWithDistances, 
        {
            'distance': Distance($feature, f, 'feet'),
            'feature': f
        }
    )
}
// Sort the candidate bus stops by distance using a custom function
function sortByDistance(a, b) {
    return a['distance'] - b['distance']
}
var sorted = Sort(featuresWithDistances, sortByDistance)
// Get the closest bus stop
var closestFeatureWithDistance = First(sorted)
// If there was no bus stop, return null
if (IsEmpty(closestFeatureWithDistance)) { return null }
// Return the bus stop name attribute value
// To customize, replace the field name "STOPNAME" below
return `${closestFeatureWithDistance['feature']['STOPNAME']}`&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2024 13:11:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-how-to-copy-date-field-intersection/m-p/1495863#M8921</guid>
      <dc:creator>cat206</dc:creator>
      <dc:date>2024-06-21T13:11:15Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade how to copy date field intersection</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-how-to-copy-date-field-intersection/m-p/1495867#M8922</link>
      <description>&lt;P&gt;I'd expect &lt;STRONG&gt;return closestFeatureWithDistance['some_date'] &lt;/STRONG&gt;would work based on how this is written. You might want to check for "no stops" earlier, though. It's possible your sorting and distance calculations are erroring out because there are no features being passed to it. Try checking for nulls prior to calculating distances.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// ...earlier stuff
var candidateStops = Intersects(busStops, bufferedLocation)

// return null if no stops
if (IsEmpty(candidateStops)) { return null }

// calculate distances, etc...&lt;/LI-CODE&gt;&lt;P&gt;It's possible the issue is specific to your data, perhaps. What does your current expression look like? When you attempt to run it, what does it return? An empty value? An error?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2024 13:21:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-how-to-copy-date-field-intersection/m-p/1495867#M8922</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2024-06-21T13:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade how to copy date field intersection</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-how-to-copy-date-field-intersection/m-p/1495878#M8923</link>
      <description>&lt;P&gt;Hi Josh,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for replying so quickly. I have amended the code slightly to match my feature layers.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// Get Species sighting layer

var Sighting = FeatureSetByName($map, "Potential Sightings to be reviewed")
// Buffer the current location and intersect with the species
var bufferedLocation = Buffer($feature, 2, 'meter')
var Species = Intersects(Sighting, bufferedLocation)
// Calculate the distance between the species and the current location
// Store the feature and distance as a dictionary and push it into an array
var featuresWithDistances = []
for (var f in Species) {
    Push(featuresWithDistances, 
        {
            'distance': Distance($feature, f, 'meter'),
            'feature': f
        }
    )
}
// Sort the species by distance using a custom function
function sortByDistance(a, b) {
    return a['distance'] - b['distance']
}
var sorted = Sort(featuresWithDistances, sortByDistance)
// Get the closest species sighting
var closestFeatureWithDistance = First(sorted)
// If there was no species, return null
if (IsEmpty(closestFeatureWithDistance)) { return null }
// Return the species name attribute value
// To customize, replace the field name "Date" below
return `${closestFeatureWithDistance['feature']['InspDate']}`&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The inspection date on the feature is fine:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cat206_0-1718976783695.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/107633i839B754626C4EB32/image-size/medium?v=v2&amp;amp;px=400" role="button" title="cat206_0-1718976783695.png" alt="cat206_0-1718976783695.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when i go to add a new feature to the new layer, it looks like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cat206_1-1718976853804.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/107636iE3F2C6D90692303B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="cat206_1-1718976853804.png" alt="cat206_1-1718976853804.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2024 13:34:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-how-to-copy-date-field-intersection/m-p/1495878#M8923</guid>
      <dc:creator>cat206</dc:creator>
      <dc:date>2024-06-21T13:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade how to copy date field intersection</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-how-to-copy-date-field-intersection/m-p/1495937#M8924</link>
      <description>&lt;P&gt;&lt;EM&gt;Curious&lt;/EM&gt;. Most datetimes are just epoch integers representing the number of milliseconds since 1/1/1970, so the fact that you're getting something an hour and &lt;EM&gt;two seconds&lt;/EM&gt; ahead of that date suggests there's something else going on with the time scale of your fields.&lt;/P&gt;&lt;P&gt;Your inspection date on the feature becomes &lt;STRONG&gt;&lt;SPAN class=""&gt;1700632800000&lt;/SPAN&gt;&lt;/STRONG&gt;. But that assumes milliseconds. Can you add this right before the end of your expression?&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Console(Number(closestFeatureWithDistance['feature']['InspDate']))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;What does the Console show?&lt;/P&gt;&lt;P&gt;If your feature is storing timestamps in &lt;EM&gt;seconds&lt;/EM&gt;, but the other layer stores them in, say &lt;EM&gt;nanoseconds&lt;/EM&gt;, that could account for the vast difference in displayed dates.&lt;/P&gt;&lt;P&gt;Assuming this might be the case, the solution is to convert the date to a number and then multiply it by whatever factor you need to get to the appropriate units.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2024 14:01:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-how-to-copy-date-field-intersection/m-p/1495937#M8924</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2024-06-21T14:01:07Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade how to copy date field intersection</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-how-to-copy-date-field-intersection/m-p/1495943#M8925</link>
      <description>&lt;P&gt;Hi Josh,&lt;/P&gt;&lt;P&gt;I've tried adding it in but it doesn't seem to be registering it which is really bizarre:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cat206_0-1718979061561.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/107640iFC09D99505708504/image-size/medium?v=v2&amp;amp;px=400" role="button" title="cat206_0-1718979061561.png" alt="cat206_0-1718979061561.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I must be going wrong somewhere but cannot figure it out&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2024 14:11:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-how-to-copy-date-field-intersection/m-p/1495943#M8925</guid>
      <dc:creator>cat206</dc:creator>
      <dc:date>2024-06-21T14:11:30Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade how to copy date field intersection</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-how-to-copy-date-field-intersection/m-p/1501766#M9030</link>
      <description>&lt;P&gt;Hi Josh,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I raised an ESRI support ticket and after some investigation, we have a solution!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Simply remove the '${....} from the last line of the script as seen below:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Previous code:&lt;/STRONG&gt; return `${closestFeatureWithDistance['feature']['Date1']}`&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Amended code:&lt;/STRONG&gt;&amp;nbsp; return closestFeatureWithDistance['feature']['Date1']&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jul 2024 10:29:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/arcade-how-to-copy-date-field-intersection/m-p/1501766#M9030</guid>
      <dc:creator>cat206</dc:creator>
      <dc:date>2024-07-05T10:29:29Z</dc:date>
    </item>
  </channel>
</rss>

