<?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: Field Maps Arcade Expression/Calculation - Only calculate for new features or when field is empty? in ArcGIS Collector Questions</title>
    <link>https://community.esri.com/t5/arcgis-collector-questions/field-maps-arcade-expression-calculation-only/m-p/1271485#M13748</link>
    <description>&lt;P&gt;I may have just solved this myself, but still open to suggestions of any improvement since I'm not well versed in Arcade!&lt;/P&gt;&lt;P&gt;I replaced $originalFeature with $feature in my IIF statement and seems to like that better.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var observationNumber = IIf(IsEmpty($feature.observation_number), yearYY+"EWB"+trapperNum+"X"+gns, $feature.observation_number)

return observationNumber&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 24 Mar 2023 18:36:29 GMT</pubDate>
    <dc:creator>BrantCarman</dc:creator>
    <dc:date>2023-03-24T18:36:29Z</dc:date>
    <item>
      <title>Field Maps Arcade Expression/Calculation - Only calculate for new features or when field is empty?</title>
      <link>https://community.esri.com/t5/arcgis-collector-questions/field-maps-arcade-expression-calculation-only/m-p/1271471#M13747</link>
      <description>&lt;P&gt;I'm working on developing a smart form for use in Field Maps, and would like a form calculation to only populate some fields when the exisiting value is empty or null.&amp;nbsp; For example, when somebody creates a new feature, I want the form to populate using the below expression.&amp;nbsp; This gives new records a uniqe "Observation number as per my expression.&lt;/P&gt;&lt;P&gt;I also want users to be able to edit features, but each time a feature is accessed in Field Maps for editing, my Observation Number is getting overwritten with a new calculation.&amp;nbsp; I've tried including If Else logic to only run the calculation when the field is empty, but it doesn't seem to be working.&lt;/P&gt;&lt;P&gt;Anybody know what I'm missing?&amp;nbsp; Thank you for your help!&lt;/P&gt;&lt;LI-CODE lang="c"&gt;//generate a "count" of milliseconds elapsed since the start of the year, 
//and combine that with trapper number and survey abreviation to create a 
//unique Observation Number.

//layout some variables to get milliseconds since the start of current year
var now = Now();
var currentYear = Year(now)
var yearStart = Date(currentYear, 0, 0);
//dateCheck variable used for testing only
var dateCheck = Date(2023, 0, 5);
var msCount = DateDiff(now, yearStart, 'milliseconds');
var charCount = Count(Text(msCount))

//Building out "Get Next Sequence" variables. 
//Basically a number that increments every 1.67 minutes
//Different gns used depending on total character count from msCount above
//(keeps the number unique when milliseconds increases from XXX,XXX to X,XXX,XXX to XX,XXX,XXX)
var gns9 = Left(msCount, 4)
var gns10 = Left(msCount, 5)
var gns11 = Left(msCount, 6)
//Return a gns value from above based on the character count of millisecond value
var gns = When(charCount == 9, gns9, charCount == 10, gns10, charCount == 11, gns11, 'ERROR');

//Get the full name of signed in user and split into an array and grab the 4th indexed value
//For this to work, full name in user profile should include: 
//First Name as a single word, and Last Name as: 
//Last Name, Program Abreviation, and TrapperNumber separated by spaces
//example: John Smith JB 1111
var user = GetUser(FeatureSetByName($map, 'Survey Sites')).fullName
var trapperNum = Split(user, ' ')[3];
var yearYY = Right(Text(currentYear), 2)

//Build a unique observation number with YY + Survey Acronym + unique surveyor ID number extracted from last name + gns millisecond value
return yearYY+"EWB"+trapperNum+"X"+gns;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's an example of the IIF logic I tried as well, replacing line 34 above:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var observationNumber = IIf(IsEmpty($feature.observation_number), yearYY+"EWB"+trapperNum+"X"+gns, $originalFeature.observation_number)

return observationNumber&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 24 Mar 2023 18:03:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-collector-questions/field-maps-arcade-expression-calculation-only/m-p/1271471#M13747</guid>
      <dc:creator>BrantCarman</dc:creator>
      <dc:date>2023-03-24T18:03:39Z</dc:date>
    </item>
    <item>
      <title>Re: Field Maps Arcade Expression/Calculation - Only calculate for new features or when field is empty?</title>
      <link>https://community.esri.com/t5/arcgis-collector-questions/field-maps-arcade-expression-calculation-only/m-p/1271485#M13748</link>
      <description>&lt;P&gt;I may have just solved this myself, but still open to suggestions of any improvement since I'm not well versed in Arcade!&lt;/P&gt;&lt;P&gt;I replaced $originalFeature with $feature in my IIF statement and seems to like that better.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var observationNumber = IIf(IsEmpty($feature.observation_number), yearYY+"EWB"+trapperNum+"X"+gns, $feature.observation_number)

return observationNumber&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 24 Mar 2023 18:36:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-collector-questions/field-maps-arcade-expression-calculation-only/m-p/1271485#M13748</guid>
      <dc:creator>BrantCarman</dc:creator>
      <dc:date>2023-03-24T18:36:29Z</dc:date>
    </item>
    <item>
      <title>Re: Field Maps Arcade Expression/Calculation - Only calculate for new features or when field is empty?</title>
      <link>https://community.esri.com/t5/arcgis-collector-questions/field-maps-arcade-expression-calculation-only/m-p/1275581#M13756</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/144848"&gt;@DonSjoboen&lt;/a&gt;&amp;nbsp; this is similar to what you are trying to do. might be worth a look to see if the solution would work for yours?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 22:26:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-collector-questions/field-maps-arcade-expression-calculation-only/m-p/1275581#M13756</guid>
      <dc:creator>VanessaSimps</dc:creator>
      <dc:date>2023-04-04T22:26:29Z</dc:date>
    </item>
  </channel>
</rss>

