<?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 Calculating unique ID field using Arcade in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/calculating-unique-id-field-using-arcade/m-p/1506307#M60299</link>
    <description>&lt;P&gt;I am attempting to calculate a unique ID in a form for newly-added features. The unique ID should conform to the pattern YYYYddddd where YYYY is the current year and ddddd is a five-digit integer sequence denoting the order in which each feature was added (e.g., 202400001). When editing an existing feature, I'd simply like the calculation to return the existing value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My calculated expression currently looks like this:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;if ($editcontext.editType == 'UPDATE') {
    if (!IsEmpty($feature["treeID"])) {
        return $feature["treeID"]
    }
else if ($editcontext.editType == "INSERT") {
    return Number(Concatenate(Year(Today()),Text(Count(Filter($featureset,left($feature["treeID"],4)+'='+Year(Today()))) + 1,'00000')))
}
}&lt;/LI-CODE&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;The Arcade code works during testing in the editor, but I receive an error (attribute failed) when attempting to add a new feature and automatically calculate the field using the form.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I would appreciate any help or advice to solve the issue!&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Wed, 17 Jul 2024 19:44:10 GMT</pubDate>
    <dc:creator>DanielBurcham</dc:creator>
    <dc:date>2024-07-17T19:44:10Z</dc:date>
    <item>
      <title>Calculating unique ID field using Arcade</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/calculating-unique-id-field-using-arcade/m-p/1506307#M60299</link>
      <description>&lt;P&gt;I am attempting to calculate a unique ID in a form for newly-added features. The unique ID should conform to the pattern YYYYddddd where YYYY is the current year and ddddd is a five-digit integer sequence denoting the order in which each feature was added (e.g., 202400001). When editing an existing feature, I'd simply like the calculation to return the existing value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My calculated expression currently looks like this:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;if ($editcontext.editType == 'UPDATE') {
    if (!IsEmpty($feature["treeID"])) {
        return $feature["treeID"]
    }
else if ($editcontext.editType == "INSERT") {
    return Number(Concatenate(Year(Today()),Text(Count(Filter($featureset,left($feature["treeID"],4)+'='+Year(Today()))) + 1,'00000')))
}
}&lt;/LI-CODE&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;The Arcade code works during testing in the editor, but I receive an error (attribute failed) when attempting to add a new feature and automatically calculate the field using the form.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I would appreciate any help or advice to solve the issue!&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 17 Jul 2024 19:44:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/calculating-unique-id-field-using-arcade/m-p/1506307#M60299</guid>
      <dc:creator>DanielBurcham</dc:creator>
      <dc:date>2024-07-17T19:44:10Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating unique ID field using Arcade</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/calculating-unique-id-field-using-arcade/m-p/1506331#M60300</link>
      <description>&lt;P&gt;Refer to existing values as&amp;nbsp;&lt;SPAN&gt;$originalFeature otherwise it's an self intersecting calculation loop&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if ($editcontext.editType == 'UPDATE') {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; if (!IsEmpty($feature["treeID"])) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return $originalFeature["treeID"]&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2024 20:29:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/calculating-unique-id-field-using-arcade/m-p/1506331#M60300</guid>
      <dc:creator>ChristopherCounsell</dc:creator>
      <dc:date>2024-07-17T20:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating unique ID field using Arcade</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/calculating-unique-id-field-using-arcade/m-p/1506336#M60301</link>
      <description>&lt;P&gt;Not sure if you also need to refer to the original feature in !isempty, test that if it doesn't work&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2024 20:32:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/calculating-unique-id-field-using-arcade/m-p/1506336#M60301</guid>
      <dc:creator>ChristopherCounsell</dc:creator>
      <dc:date>2024-07-17T20:32:32Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating unique ID field using Arcade</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/calculating-unique-id-field-using-arcade/m-p/1506349#M60302</link>
      <description>&lt;P&gt;Thank you for the suggestion! The change does not seem to work. I tried using 'originalFeature' in both ways, but I still receive an error when creating a new feature. Though, it seems to work fine when editing existing features.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2024 20:51:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/calculating-unique-id-field-using-arcade/m-p/1506349#M60302</guid>
      <dc:creator>DanielBurcham</dc:creator>
      <dc:date>2024-07-17T20:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating unique ID field using Arcade</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/calculating-unique-id-field-using-arcade/m-p/1506458#M60307</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/692560"&gt;@DanielBurcham&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Could you try this?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;if($editcontext.editType=="INSERT" || ($editcontext.editType == "UPDATE" &amp;amp;&amp;amp; IsEmpty($feature.treeID) ))
{
#code to calculate the unique ID
}
else {$feature.tree.ID}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2024 04:39:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/calculating-unique-id-field-using-arcade/m-p/1506458#M60307</guid>
      <dc:creator>gis_KIWI4</dc:creator>
      <dc:date>2024-07-18T04:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating unique ID field using Arcade</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/calculating-unique-id-field-using-arcade/m-p/1506477#M60308</link>
      <description>&lt;P&gt;It worked! Thank you for the solution. For anyone interested, here's the final version of my working code:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;if ($editcontext.editType == 'INSERT' || ($editcontext.editType == 'UPDATE' &amp;amp;&amp;amp; IsEmpty($feature["treeID"]))) {
    return Number(Concatenate(Year(Today()),Text(Count(Filter($layer,"CREATIONDATE &amp;gt; DATE '2024-01-01'")) + 1,'00000')))
    }
else {
    return $originalFeature["treeID"]
}&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 18 Jul 2024 05:43:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/calculating-unique-id-field-using-arcade/m-p/1506477#M60308</guid>
      <dc:creator>DanielBurcham</dc:creator>
      <dc:date>2024-07-18T05:43:21Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating unique ID field using Arcade</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/calculating-unique-id-field-using-arcade/m-p/1525559#M61039</link>
      <description>&lt;P&gt;Can someone help me please? The above example works 100% but I want to add a text prefix to the output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example: ABC2020400001&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate your help.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2024 02:12:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/calculating-unique-id-field-using-arcade/m-p/1525559#M61039</guid>
      <dc:creator>StephanLe_Roux</dc:creator>
      <dc:date>2024-08-22T02:12:54Z</dc:date>
    </item>
  </channel>
</rss>

