<?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: Populate UID field in new feature with Object ID value (Arcade) in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/populate-uid-field-in-new-feature-with-object-id/m-p/1405512#M58461</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/293417"&gt;@JasonFitzsimmons&lt;/a&gt;&amp;nbsp; -&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;You could use the (&amp;nbsp;&lt;SPAN&gt;$editcontext&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;editType&lt;/SPAN&gt;&lt;SPAN&gt;==&lt;/SPAN&gt;&lt;SPAN&gt;"INSERT" ) to control the field being calculate during the creation of the record but this will still be problematic if you plan on using Object ID. You cannot use the ObjectID during insert because it doesn't exist.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Okay there a few other option we could explore.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;1) &lt;STRONG&gt;&lt;U&gt;Calculating ObjectID from the feature layer&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Get the max ObjectID from the feature layer and add one to it to get the next object ID.&lt;BR /&gt;The edit context type will ensure it only fires when its a new record and since it is a calculated field it will not be editable in form.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;if($editcontext.editType=="INSERT")
//do the following only if the edit type is insert
{
var x = FeatureSetByName($datastore, "TEST", ["OBJECTID"], false)
if (count(x) &amp;gt; 0)
return Max(x,"OBJECTID")+1
else 
return 1
}
else 
{
return $feature.UID2
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="gis_KIWI4_0-1712183346051.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/99960iF0EB8DB611BA3620/image-size/medium?v=v2&amp;amp;px=400" role="button" title="gis_KIWI4_0-1712183346051.png" alt="gis_KIWI4_0-1712183346051.png" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;gis_KIWI4_0-1712183346051.png&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The first record will be different for the reason that there is no OBJECTID present to calculate the&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="gis_KIWI4_1-1712183377671.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/99961iD5C8C7C5827BEF23/image-size/medium?v=v2&amp;amp;px=400" role="button" title="gis_KIWI4_1-1712183377671.png" alt="gis_KIWI4_1-1712183377671.png" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;gis_KIWI4_1-1712183377671.png&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;2) &lt;U&gt;&lt;STRONG&gt;Use CurrentDateTime to get a unique value&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;If you need a unique number then you could consider creating one out of the date time.&amp;nbsp;&lt;BR /&gt;Solution 1 relies on reading the feature layer and I think the number of records could affect performance but with this approach, it will be agnostic of the number of records while giving a unique value. (feel free to add miliseconds to the end if you wanted to be 100% sure :D)&lt;/P&gt;&lt;LI-CODE lang="c"&gt;if($editcontext.editType=="INSERT")
{
var x = now()
var y = text(x,'YMMDDhhss')
return y
}
else {
  return $feature.UID3
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="gis_KIWI4_2-1712183625011.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/99962iE7225F1E5ACED490/image-size/medium?v=v2&amp;amp;px=400" role="button" title="gis_KIWI4_2-1712183625011.png" alt="gis_KIWI4_2-1712183625011.png" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;gis_KIWI4_2-1712183625011.png&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3) While the above 2 may do the trick, I think the most robust solution would be using GUID function in arcade.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/arcade/function-reference/text_functions/#guidguidformat---text" target="_blank"&gt;https://developers.arcgis.com/arcade/function-reference/text_functions/#guidguidformat---text&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Hope this helps&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 03 Apr 2024 22:38:48 GMT</pubDate>
    <dc:creator>gis_KIWI4</dc:creator>
    <dc:date>2024-04-03T22:38:48Z</dc:date>
    <item>
      <title>Populate UID field in new feature with Object ID value (Arcade)</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/populate-uid-field-in-new-feature-with-object-id/m-p/1405332#M58454</link>
      <description>&lt;P&gt;We have a feature layer in a web map that is basis of an editor using Experience Builder.&amp;nbsp; &amp;nbsp;The clients should be able to create new features as well as edit existing features in the app.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Due to some scripts being used, we need a 'UID' field of unique numeric IDs.&lt;BR /&gt;&lt;BR /&gt;It will work for our purpose if we can grab the value in the Object ID field&amp;nbsp; and populate the UID field with this value when a new feature is created.&lt;BR /&gt;&lt;BR /&gt;So far I am not finding any Arcade snippets that may work for this. Ideally this value would be written during the feature creation in the app, but then not editable.&lt;BR /&gt;&lt;BR /&gt;Ideas?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2024 17:30:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/populate-uid-field-in-new-feature-with-object-id/m-p/1405332#M58454</guid>
      <dc:creator>JasonFitzsimmons</dc:creator>
      <dc:date>2024-04-03T17:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: Populate UID field in new feature with Object ID value (Arcade)</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/populate-uid-field-in-new-feature-with-object-id/m-p/1405512#M58461</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/293417"&gt;@JasonFitzsimmons&lt;/a&gt;&amp;nbsp; -&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;You could use the (&amp;nbsp;&lt;SPAN&gt;$editcontext&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;editType&lt;/SPAN&gt;&lt;SPAN&gt;==&lt;/SPAN&gt;&lt;SPAN&gt;"INSERT" ) to control the field being calculate during the creation of the record but this will still be problematic if you plan on using Object ID. You cannot use the ObjectID during insert because it doesn't exist.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Okay there a few other option we could explore.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;1) &lt;STRONG&gt;&lt;U&gt;Calculating ObjectID from the feature layer&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Get the max ObjectID from the feature layer and add one to it to get the next object ID.&lt;BR /&gt;The edit context type will ensure it only fires when its a new record and since it is a calculated field it will not be editable in form.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;if($editcontext.editType=="INSERT")
//do the following only if the edit type is insert
{
var x = FeatureSetByName($datastore, "TEST", ["OBJECTID"], false)
if (count(x) &amp;gt; 0)
return Max(x,"OBJECTID")+1
else 
return 1
}
else 
{
return $feature.UID2
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="gis_KIWI4_0-1712183346051.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/99960iF0EB8DB611BA3620/image-size/medium?v=v2&amp;amp;px=400" role="button" title="gis_KIWI4_0-1712183346051.png" alt="gis_KIWI4_0-1712183346051.png" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;gis_KIWI4_0-1712183346051.png&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The first record will be different for the reason that there is no OBJECTID present to calculate the&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="gis_KIWI4_1-1712183377671.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/99961iD5C8C7C5827BEF23/image-size/medium?v=v2&amp;amp;px=400" role="button" title="gis_KIWI4_1-1712183377671.png" alt="gis_KIWI4_1-1712183377671.png" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;gis_KIWI4_1-1712183377671.png&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;2) &lt;U&gt;&lt;STRONG&gt;Use CurrentDateTime to get a unique value&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;If you need a unique number then you could consider creating one out of the date time.&amp;nbsp;&lt;BR /&gt;Solution 1 relies on reading the feature layer and I think the number of records could affect performance but with this approach, it will be agnostic of the number of records while giving a unique value. (feel free to add miliseconds to the end if you wanted to be 100% sure :D)&lt;/P&gt;&lt;LI-CODE lang="c"&gt;if($editcontext.editType=="INSERT")
{
var x = now()
var y = text(x,'YMMDDhhss')
return y
}
else {
  return $feature.UID3
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="gis_KIWI4_2-1712183625011.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/99962iE7225F1E5ACED490/image-size/medium?v=v2&amp;amp;px=400" role="button" title="gis_KIWI4_2-1712183625011.png" alt="gis_KIWI4_2-1712183625011.png" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;gis_KIWI4_2-1712183625011.png&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3) While the above 2 may do the trick, I think the most robust solution would be using GUID function in arcade.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/arcade/function-reference/text_functions/#guidguidformat---text" target="_blank"&gt;https://developers.arcgis.com/arcade/function-reference/text_functions/#guidguidformat---text&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Hope this helps&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2024 22:38:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/populate-uid-field-in-new-feature-with-object-id/m-p/1405512#M58461</guid>
      <dc:creator>gis_KIWI4</dc:creator>
      <dc:date>2024-04-03T22:38:48Z</dc:date>
    </item>
    <item>
      <title>Re: Populate UID field in new feature with Object ID value (Arcade)</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/populate-uid-field-in-new-feature-with-object-id/m-p/1406337#M58495</link>
      <description>&lt;P&gt;Thanks! we have actually been looking at both of these options.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2024 13:53:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/populate-uid-field-in-new-feature-with-object-id/m-p/1406337#M58495</guid>
      <dc:creator>JasonFitzsimmons</dc:creator>
      <dc:date>2024-04-05T13:53:21Z</dc:date>
    </item>
  </channel>
</rss>

