<?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: Custom primary key for relationships? in ArcGIS Field Maps Questions</title>
    <link>https://community.esri.com/t5/arcgis-field-maps-questions/custom-primary-key-for-relationships/m-p/1205130#M4355</link>
    <description>&lt;P&gt;Check if there is already a LeakID. If so, just return that, essentially changing nothing.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;if($feature.LeakID != null) {
    return $feature.LeakID
}
var AllLeaks = FeatureSetByName($map,"Gas Leak")
var LeakCount = Count(AllLeaks);
var NewestLeak = First(OrderBy(AllLeaks,"LeakID DESC"));
if(LeakCount == 0){
    return 1
}
return sum(NewestLeak.LeakID, 1);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 22 Aug 2022 19:52:55 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2022-08-22T19:52:55Z</dc:date>
    <item>
      <title>Custom primary key for relationships?</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/custom-primary-key-for-relationships/m-p/1205126#M4354</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I posted a few days ago about an issue I was having with related records in an arcade expression not evaluating correctly. I came to find out that the globalID (which I always use as my primary key) was not populating until after the submission of a feature, therefore affecting my sql statement to look into the related records. To fix this, I created a new primary key field and used that for my relationships. I then added this code:&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;var AllLeaks = FeatureSetByName($map,"Gas Leak")&lt;BR /&gt;var LeakCount = Count(AllLeaks);&lt;BR /&gt;var NewestLeak = First(OrderBy(AllLeaks,"LeakID DESC"));&lt;BR /&gt;if(LeakCount == 0){&lt;BR /&gt;return 1&lt;BR /&gt;} else {&lt;BR /&gt;return sum(NewestLeak.LeakID, 1);&lt;BR /&gt;}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;... to make my own auto-incrementing key. The problem with this is, that if I have to go back into an already-submitted feature to edit something, it renumbers this LeakID, and the relationships are gone. Is there a way with Arcade that I can tell it to only evaluate this code on the creation of a new feature and not when updating it? or is there a better way of doing what I'm doing? I also tried to have it do a compare of the object ID of this feature to the newest feature to stop it from updating, but that doesn't seem to work. I would like to keep the end users from having to enter their own leak number if possible.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Damon&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 19:37:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/custom-primary-key-for-relationships/m-p/1205126#M4354</guid>
      <dc:creator>DamonBreen</dc:creator>
      <dc:date>2022-08-22T19:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: Custom primary key for relationships?</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/custom-primary-key-for-relationships/m-p/1205130#M4355</link>
      <description>&lt;P&gt;Check if there is already a LeakID. If so, just return that, essentially changing nothing.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;if($feature.LeakID != null) {
    return $feature.LeakID
}
var AllLeaks = FeatureSetByName($map,"Gas Leak")
var LeakCount = Count(AllLeaks);
var NewestLeak = First(OrderBy(AllLeaks,"LeakID DESC"));
if(LeakCount == 0){
    return 1
}
return sum(NewestLeak.LeakID, 1);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 19:52:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/custom-primary-key-for-relationships/m-p/1205130#M4355</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-08-22T19:52:55Z</dc:date>
    </item>
    <item>
      <title>Re: Custom primary key for relationships?</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/custom-primary-key-for-relationships/m-p/1205131#M4356</link>
      <description>&lt;P&gt;Also, not sure if that applies to FIeldMaps, but in an Enterprise GDB, you can &lt;A href="https://pro.arcgis.com/en/pro-app/2.8/tool-reference/data-management/create-database-sequence.htm" target="_blank" rel="noopener"&gt;create a database sequence&lt;/A&gt;&amp;nbsp;and then call &lt;A href="https://developers.arcgis.com/arcade/function-reference/data_functions/#nextsequencevalue" target="_blank" rel="noopener"&gt;NextSequenceValue&lt;/A&gt; in Arcade instead of loading and ordering the whole featureset.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 19:56:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/custom-primary-key-for-relationships/m-p/1205131#M4356</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-08-22T19:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: Custom primary key for relationships?</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/custom-primary-key-for-relationships/m-p/1205132#M4357</link>
      <description>&lt;P&gt;Very weird, I thought I had tried this basically already with IsEmpty() and it did not work, but this in fact does work.&lt;/P&gt;&lt;P&gt;Thank you very much!&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 19:56:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/custom-primary-key-for-relationships/m-p/1205132#M4357</guid>
      <dc:creator>DamonBreen</dc:creator>
      <dc:date>2022-08-22T19:56:23Z</dc:date>
    </item>
  </channel>
</rss>

