<?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 Calculation rules for date entry in Attribute Rules Questions</title>
    <link>https://community.esri.com/t5/attribute-rules-questions/field-calculation-rules-for-date-entry/m-p/1292975#M930</link>
    <description>&lt;P&gt;The behavior you want isn't that simple...&lt;/P&gt;&lt;P&gt;Your two rules influence each other. The first rule looks at the field that gets changed by the second rule and vice versa. It might be better to do it in one rule:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Calculation Attribute RUle
// field: empty!
// triggers: update

var lifecycle = $feature.TextField1
var old_lifecycle = $originalfeature.TextField1
var retire_date = $feature.DateField1
var old_retire_date = $originalfeature.DateField1


// Was the date changed to a non-null value?
var abandon_feature = retire_date != null &amp;amp;&amp;amp; retire_date != old_retire_date

// Was the lifecycle changed to "ABANDONED"?
var feature_was_abandoned = lifecycle == "ABANDONED" &amp;amp;&amp;amp; lifecycle != old_lifecycle

// Calculate the new values
var new_retire_date = When(
    abandon_feature, retire_date,      // the date was changed by the user, use that value
    feature_was_abandoned, Date(),     // the lifecycle was changed to "ABANDONED", use current date
    lifecycle != "ABANDONED", null,    // the feature is not abandoned, set the date to null
    retire_date                        // the feature is abandoned, some other field was updated, use existing value
)
var new_lifecycle = IIf(
    abandon_feature, "ABANDONED",    // the date was changed by the user, abandon the feature
    lifecycle                        // some other field was updated, use the existing value
)

return {
    result: {attributes: {
        DateField1: new_retire_date,
        TextField1: new_lifecycle
    }}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Change the field names in lines 5-8 and 31-32.&lt;/P&gt;</description>
    <pubDate>Thu, 25 May 2023 11:16:15 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2023-05-25T11:16:15Z</dc:date>
    <item>
      <title>Field Calculation rules for date entry</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/field-calculation-rules-for-date-entry/m-p/1292773#M925</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to create some attribute rules to work with our Cartegraph instance so we can keep track of data that has been retired by our Public Works crews. I have created two simple expressions to calculate a date field and to alter a lifecycle field, but they will not allow me to manually populate the date field and retire a feature.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are the two expressions, the first calculates the date for a feature thats lifecycle is not asbuilt or unknown. The second is supposed to calculate the lifecycle as abandoned if there is a date in the CarteRetire field. I assume the majority of the problem lies in the second expression; I am not very good at scripting yet. Both of these are set to trigger on updates only.&lt;/P&gt;&lt;P&gt;if ($feature.LIFECYCLE == "ASBUILT,UNKNOWN" || $feature.LIFECYCLE == $originalfeature.LIFECYCLE){&lt;BR /&gt;return NULL&lt;BR /&gt;} else {&lt;BR /&gt;return Date()&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if (IsEmpty($feature.CarteRetire))&lt;BR /&gt;return $feature.LIFECYCLE&lt;BR /&gt;else {&lt;BR /&gt;return "ABANDONED"&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2023 19:34:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/field-calculation-rules-for-date-entry/m-p/1292773#M925</guid>
      <dc:creator>CodyYager</dc:creator>
      <dc:date>2023-05-24T19:34:28Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculation rules for date entry</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/field-calculation-rules-for-date-entry/m-p/1292969#M929</link>
      <description>&lt;P&gt;You are missing brackets on the first if statement&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;if (IsEmpty($feature.CarteRetire)){
  return $feature.LIFECYCLE
}
else {
  return "ABANDONED"
}&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 25 May 2023 10:48:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/field-calculation-rules-for-date-entry/m-p/1292969#M929</guid>
      <dc:creator>MikeMillerGIS</dc:creator>
      <dc:date>2023-05-25T10:48:15Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculation rules for date entry</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/field-calculation-rules-for-date-entry/m-p/1292975#M930</link>
      <description>&lt;P&gt;The behavior you want isn't that simple...&lt;/P&gt;&lt;P&gt;Your two rules influence each other. The first rule looks at the field that gets changed by the second rule and vice versa. It might be better to do it in one rule:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Calculation Attribute RUle
// field: empty!
// triggers: update

var lifecycle = $feature.TextField1
var old_lifecycle = $originalfeature.TextField1
var retire_date = $feature.DateField1
var old_retire_date = $originalfeature.DateField1


// Was the date changed to a non-null value?
var abandon_feature = retire_date != null &amp;amp;&amp;amp; retire_date != old_retire_date

// Was the lifecycle changed to "ABANDONED"?
var feature_was_abandoned = lifecycle == "ABANDONED" &amp;amp;&amp;amp; lifecycle != old_lifecycle

// Calculate the new values
var new_retire_date = When(
    abandon_feature, retire_date,      // the date was changed by the user, use that value
    feature_was_abandoned, Date(),     // the lifecycle was changed to "ABANDONED", use current date
    lifecycle != "ABANDONED", null,    // the feature is not abandoned, set the date to null
    retire_date                        // the feature is abandoned, some other field was updated, use existing value
)
var new_lifecycle = IIf(
    abandon_feature, "ABANDONED",    // the date was changed by the user, abandon the feature
    lifecycle                        // some other field was updated, use the existing value
)

return {
    result: {attributes: {
        DateField1: new_retire_date,
        TextField1: new_lifecycle
    }}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Change the field names in lines 5-8 and 31-32.&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2023 11:16:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/field-calculation-rules-for-date-entry/m-p/1292975#M930</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-05-25T11:16:15Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculation rules for date entry</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/field-calculation-rules-for-date-entry/m-p/1293054#M931</link>
      <description>&lt;P&gt;Thank you! I had a feeling it was going to be a bit more complex than what I had originally planned.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2023 14:11:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/field-calculation-rules-for-date-entry/m-p/1293054#M931</guid>
      <dc:creator>CodyYager</dc:creator>
      <dc:date>2023-05-25T14:11:13Z</dc:date>
    </item>
  </channel>
</rss>

