<?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: Return value automatically cast to output field type? in Attribute Rules Questions</title>
    <link>https://community.esri.com/t5/attribute-rules-questions/return-value-gets-automatically-cast-to-output/m-p/1152085#M341</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;Is that correct?&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;No.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;What it means is:&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN&gt;If you don't do it yourself, the Attribute Rule will take care of the conversion between the data types.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;To be sure about the results (which should be best practice), you should do it yourself.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Take this rule:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// converts the value from the text field to integer and double
var txt = $feature.TextField
if(IsEmpty(txt)) { return }
return {"result": {"attributes": {"IntegerField": txt, "DoubleField": txt}}}&lt;/LI-CODE&gt;&lt;P&gt;I'm not doing any type casting here. I return text values for numeric fields, ArcGIS automatically takes care of the conversion. Great, less work for me! Let's see how that turns out:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1646824249719.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35924i3C1EDF25F71D0FC8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1646824249719.png" alt="JohannesLindner_0-1646824249719.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Uh oh, something is wrong here...&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I'm German, and we (and also the German ArcGIS locationing) use comma as decimal separator and dot as thousands separator. If I input numbers in American format as text (stupid, but just as an example), I get unexpected results.&lt;/LI&gt;&lt;LI&gt;I expected &lt;STRONG&gt;int(1.5)&lt;/STRONG&gt; to be &lt;STRONG&gt;floor(1.5) = 1&lt;/STRONG&gt;, but ArcGIS uses &lt;STRONG&gt;Round(1.5) = 2&lt;/STRONG&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;So the Attribute Rule automatically casted between the data types, but to be sure about the results I get (again. that should be best practice), I should do it myself:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var txt = $feature.TextField
if(IsEmpty(txt)) { return }

txt = Replace(txt, ",", "")  // remove American thousands separator
txt = Replace(txt, ".", ",") // replace decimal separator
var dbl = Number(txt)
var int = Floor(dbl)
return {"result": {"attributes": {"IntegerField": int, "DoubleField": dbl}}}&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_1-1646825223713.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35927i35C1472CE81BB07F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_1-1646825223713.png" alt="JohannesLindner_1-1646825223713.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Same concept applies to conversion from and to date. Probably more so, seeing how many different date formats there are...&lt;/P&gt;&lt;P&gt;As for geometries: Yes, you just return the Polyline, which is already a Geometry.&lt;/P&gt;</description>
    <pubDate>Wed, 09 Mar 2022 11:32:58 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2022-03-09T11:32:58Z</dc:date>
    <item>
      <title>Return value gets automatically cast to output field type?</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/return-value-gets-automatically-cast-to-output/m-p/1151985#M339</link>
      <description>&lt;P&gt;&lt;BR /&gt;The Arcade developer&amp;nbsp;&lt;A href="https://developers.arcgis.com/arcade/guide/profiles/#attribute-rule-calculation" target="_self"&gt;Attribute Rule Calculation&lt;/A&gt; docs say:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;When the attribute rule is evaluated for a dataset, the return value for the expression is cast to the field type of the output value. &lt;STRONG&gt;It is best practice&lt;/STRONG&gt; to handle casting within the script for full control of casting behavior to&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;A href="https://developers.arcgis.com/arcade/guide/types/#number" target="_blank" rel="noopener"&gt;Number&lt;/A&gt;,&amp;nbsp;&lt;A href="https://developers.arcgis.com/arcade/guide/types/#date" target="_blank" rel="noopener"&gt;Date&lt;/A&gt;, or&amp;nbsp;&lt;A href="https://developers.arcgis.com/arcade/guide/types/#text" target="_blank" rel="noopener"&gt;Text&lt;/A&gt;&amp;nbsp;return types.&lt;/STRONG&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;It sounds like that second sentence is implying that we only need to cast datatypes to the output type when the datatype is&amp;nbsp;&lt;EM&gt;Number,&amp;nbsp;Date, or&amp;nbsp;Text&lt;/EM&gt;.&lt;/P&gt;&lt;P&gt;Is that correct?&lt;/P&gt;&lt;P&gt;For example, for geometries, would we return&amp;nbsp;&lt;FONT face="courier new,courier" color="#0000FF"&gt;Polyline(my_dictionary)&lt;/FONT&gt; -- and then rely on Arcade to automatically cast that polyline to a geometry?&lt;/P&gt;&lt;P&gt;Or is the fact that &lt;A href="https://community.esri.com/t5/arcgis-pro-questions/what-is-the-hierarchical-structure-of-arcade/m-p/1150137#M52281" target="_self"&gt;Polyline is a subtype of the Geometry type&lt;/A&gt; mean that Polyline is technically already a geometry?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Mar 2022 00:51:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/return-value-gets-automatically-cast-to-output/m-p/1151985#M339</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2022-03-13T00:51:20Z</dc:date>
    </item>
    <item>
      <title>Re: Return value automatically cast to output field type?</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/return-value-gets-automatically-cast-to-output/m-p/1152085#M341</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;Is that correct?&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;No.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;What it means is:&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN&gt;If you don't do it yourself, the Attribute Rule will take care of the conversion between the data types.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;To be sure about the results (which should be best practice), you should do it yourself.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Take this rule:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// converts the value from the text field to integer and double
var txt = $feature.TextField
if(IsEmpty(txt)) { return }
return {"result": {"attributes": {"IntegerField": txt, "DoubleField": txt}}}&lt;/LI-CODE&gt;&lt;P&gt;I'm not doing any type casting here. I return text values for numeric fields, ArcGIS automatically takes care of the conversion. Great, less work for me! Let's see how that turns out:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1646824249719.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35924i3C1EDF25F71D0FC8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1646824249719.png" alt="JohannesLindner_0-1646824249719.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Uh oh, something is wrong here...&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I'm German, and we (and also the German ArcGIS locationing) use comma as decimal separator and dot as thousands separator. If I input numbers in American format as text (stupid, but just as an example), I get unexpected results.&lt;/LI&gt;&lt;LI&gt;I expected &lt;STRONG&gt;int(1.5)&lt;/STRONG&gt; to be &lt;STRONG&gt;floor(1.5) = 1&lt;/STRONG&gt;, but ArcGIS uses &lt;STRONG&gt;Round(1.5) = 2&lt;/STRONG&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;So the Attribute Rule automatically casted between the data types, but to be sure about the results I get (again. that should be best practice), I should do it myself:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var txt = $feature.TextField
if(IsEmpty(txt)) { return }

txt = Replace(txt, ",", "")  // remove American thousands separator
txt = Replace(txt, ".", ",") // replace decimal separator
var dbl = Number(txt)
var int = Floor(dbl)
return {"result": {"attributes": {"IntegerField": int, "DoubleField": dbl}}}&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_1-1646825223713.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35927i35C1472CE81BB07F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_1-1646825223713.png" alt="JohannesLindner_1-1646825223713.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Same concept applies to conversion from and to date. Probably more so, seeing how many different date formats there are...&lt;/P&gt;&lt;P&gt;As for geometries: Yes, you just return the Polyline, which is already a Geometry.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2022 11:32:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/return-value-gets-automatically-cast-to-output/m-p/1152085#M341</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-03-09T11:32:58Z</dc:date>
    </item>
  </channel>
</rss>

