<?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 Re: Calculated Expression Error: Failed to Calculate in ArcGIS Field Maps Questions</title>
    <link>https://community.esri.com/t5/arcgis-field-maps-questions/calculated-expression-error-failed-to-calculate/m-p/1206353#M4385</link>
    <description>&lt;P&gt;Thanks for the reply. I'm assuming that the Sort function is correct. I got it from #7 from this &lt;A href="https://www.esri.com/arcgis-blog/products/field-maps/field-mobility/common-calculated-expressions-for-arcgis-field-maps/" target="_blank" rel="noopener"&gt;ESRI blog article&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 25 Aug 2022 14:58:37 GMT</pubDate>
    <dc:creator>michael_vetter</dc:creator>
    <dc:date>2022-08-25T14:58:37Z</dc:date>
    <item>
      <title>Calculated Expression Error: Failed to Calculate</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/calculated-expression-error-failed-to-calculate/m-p/1199383#M4247</link>
      <description>&lt;P&gt;I'm trying to use a calculated expression to auto populate several fields in a layer that I'm collecting. I have 3 expressions that are doing basically the same thing, but only 2 of the 3 expressions work. I get an error that says Failed to Calculate and because of this error I can't submit the collected point. Below is the Arcade expression that I'm using. The 3 calculated expressions are using this same code, but pulling data from different layers from the map.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;if (IsEmpty(Geometry($feature))){
    return null
}

var parcels = FeatureSetByName($map,"Parcels")

var bufferedLocation = Buffer($feature, 100, "feet")
var candidateParcels = Intersects(parcels, bufferedLocation)

var featuresWithDistances = []
for (var f in candidateParcels){
    Push(featuresWithDistances,
        {
            "distance": Distance($feature, f, "feet"),
            "feature": f
        }
    )
}

function sortByDistance(a,b){
    return a["distance"] - b["distance"]
}

var sorted = Sort(featuresWithDistances, sortByDistance)

var closestFeatureWithDistance = First(sorted)

if (IsEmpty(closestFeatureWithDistance)){
    return null
}

return `${closestFeatureWithDistance["feature"]["ADDRESS"]}`&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2022 14:11:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/calculated-expression-error-failed-to-calculate/m-p/1199383#M4247</guid>
      <dc:creator>michael_vetter</dc:creator>
      <dc:date>2022-08-04T14:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated Expression Error: Failed to Calculate</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/calculated-expression-error-failed-to-calculate/m-p/1199406#M4248</link>
      <description>&lt;P&gt;Are you the correct Sort function? This is what is used to sort distance in other examples&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function compareDistance(a,b){
  if(a['Distance']&amp;lt;b['Distance'])
    return -1;
  if(a['Distance']&amp;gt;b['Distance'])
    return 1;
  return 0;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2022 14:49:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/calculated-expression-error-failed-to-calculate/m-p/1199406#M4248</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2022-08-04T14:49:00Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated Expression Error: Failed to Calculate</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/calculated-expression-error-failed-to-calculate/m-p/1199423#M4249</link>
      <description>&lt;P&gt;Checking the Field Map's logs will probably give you insight to why it failed to calc.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;You also make sure that the layer you are using (featureSetByName) loads successfully in Field Maps.&amp;nbsp; Since you are working with Geometry you might also make sure it is drawing at the map scale you&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many of the geometry functions are subject to map scale. Including Buffer, Distance and Intersect.&amp;nbsp; You may be running into a scenario here that isn't trapped by one of your "return null" checks.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/arcade/function-reference/geometry_functions/#distance" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/arcade/function-reference/geometry_functions/#distance&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Be aware that using&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;$feature&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales.&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://developers.arcgis.com/arcade/function-reference/geometry_functions/#" target="_blank" rel="noopener"&gt;Read more here&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2022 15:24:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/calculated-expression-error-failed-to-calculate/m-p/1199423#M4249</guid>
      <dc:creator>JustinReynolds</dc:creator>
      <dc:date>2022-08-04T15:24:52Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated Expression Error: Failed to Calculate</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/calculated-expression-error-failed-to-calculate/m-p/1206350#M4384</link>
      <description>&lt;P&gt;Justin,&lt;/P&gt;&lt;P&gt;I took a look at the logs and I saw that the error was "The target server failed to respond" so I changed the layer to a more reliable one and now it's working as expected. Thanks for your help.&lt;/P&gt;&lt;P&gt;Michael&lt;/P&gt;</description>
      <pubDate>Thu, 25 Aug 2022 14:56:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/calculated-expression-error-failed-to-calculate/m-p/1206350#M4384</guid>
      <dc:creator>michael_vetter</dc:creator>
      <dc:date>2022-08-25T14:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated Expression Error: Failed to Calculate</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/calculated-expression-error-failed-to-calculate/m-p/1206353#M4385</link>
      <description>&lt;P&gt;Thanks for the reply. I'm assuming that the Sort function is correct. I got it from #7 from this &lt;A href="https://www.esri.com/arcgis-blog/products/field-maps/field-mobility/common-calculated-expressions-for-arcgis-field-maps/" target="_blank" rel="noopener"&gt;ESRI blog article&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Aug 2022 14:58:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/calculated-expression-error-failed-to-calculate/m-p/1206353#M4385</guid>
      <dc:creator>michael_vetter</dc:creator>
      <dc:date>2022-08-25T14:58:37Z</dc:date>
    </item>
  </channel>
</rss>

