<?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 Calculation rule to create new feature (copy selected feature) in Attribute Rules Questions</title>
    <link>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-to-create-new-feature-copy/m-p/1190937#M464</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm new to arcade and I'm trying to setup an immediate calculation rule where if the user updates the status to "replaced", the script will make a copy of the selected line feature with the same attributes and also update a field of the $feature.&amp;nbsp; I've got the update a field part working, but cannot seem to get the create new line feature with same attributes values going.&amp;nbsp; I'm not sure if i'm using the Dictionary and Feature functions properly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some of the fields are read only as they may be used for editor tracking, etc.&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&amp;nbsp; Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if ($feature.Status =='REPLACED'){&lt;/P&gt;&lt;P&gt;&amp;nbsp; var attributes = Dictionary(Text($feature))["attributes"]&lt;/P&gt;&lt;P&gt;&amp;nbsp; Feature(Geometry($feature), attributes)&lt;BR /&gt;&amp;nbsp; return 2022&lt;BR /&gt;}&lt;BR /&gt;else {&lt;BR /&gt;&amp;nbsp; return -9999&lt;BR /&gt;}&lt;/P&gt;</description>
    <pubDate>Fri, 08 Jul 2022 17:55:59 GMT</pubDate>
    <dc:creator>AndrewKan</dc:creator>
    <dc:date>2022-07-08T17:55:59Z</dc:date>
    <item>
      <title>Calculation rule to create new feature (copy selected feature)</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-to-create-new-feature-copy/m-p/1190937#M464</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm new to arcade and I'm trying to setup an immediate calculation rule where if the user updates the status to "replaced", the script will make a copy of the selected line feature with the same attributes and also update a field of the $feature.&amp;nbsp; I've got the update a field part working, but cannot seem to get the create new line feature with same attributes values going.&amp;nbsp; I'm not sure if i'm using the Dictionary and Feature functions properly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some of the fields are read only as they may be used for editor tracking, etc.&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&amp;nbsp; Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if ($feature.Status =='REPLACED'){&lt;/P&gt;&lt;P&gt;&amp;nbsp; var attributes = Dictionary(Text($feature))["attributes"]&lt;/P&gt;&lt;P&gt;&amp;nbsp; Feature(Geometry($feature), attributes)&lt;BR /&gt;&amp;nbsp; return 2022&lt;BR /&gt;}&lt;BR /&gt;else {&lt;BR /&gt;&amp;nbsp; return -9999&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 17:55:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-to-create-new-feature-copy/m-p/1190937#M464</guid>
      <dc:creator>AndrewKan</dc:creator>
      <dc:date>2022-07-08T17:55:59Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation rule to create new feature (copy selected feature)</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-to-create-new-feature-copy/m-p/1190961#M465</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/148825"&gt;@AndrewKan&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There isn't any functionality for arcade to create a feature. If you are looking to create features for based on new inputs from the field, then the only way to do so would be to create a separate python script. You can then schedule a script to run via bat file and have windows task scheduler run it on a schedule. That is the only way, as far as I know, that would work for what you are trying to achieve.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 18:55:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-to-create-new-feature-copy/m-p/1190961#M465</guid>
      <dc:creator>RPGIS</dc:creator>
      <dc:date>2022-07-08T18:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation rule to create new feature (copy selected feature)</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-to-create-new-feature-copy/m-p/1191331#M468</link>
      <description>&lt;P&gt;Hmm... that's too bad.&amp;nbsp; Thanks for the info.&lt;/P&gt;&lt;P&gt;I had thought that the Feature data function would be able to create new features, but I guess I misinterpreted it.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/arcade/function-reference/data_functions/#feature" target="_blank"&gt;https://developers.arcgis.com/arcade/function-reference/data_functions/#feature&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jul 2022 18:36:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-to-create-new-feature-copy/m-p/1191331#M468</guid>
      <dc:creator>AndrewKan</dc:creator>
      <dc:date>2022-07-11T18:36:04Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation rule to create new feature (copy selected feature)</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-to-create-new-feature-copy/m-p/1194346#M475</link>
      <description>&lt;P&gt;You can absolutely create (and update or delete) features in the same table or even different tables using attribute rules. The trick is to not return a value, but a dictionary, using special dictionary keys:&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/2.9/help/data/geodatabases/overview/attribute-rule-dictionary-keywords.htm" target="_blank"&gt;Attribute rule dictionary keywords—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For your case, the rule would look somewhat like this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// calculation attribute rule
// triggers: (Insert,) Update
// Exclude from application evaluation!

// if status did not change to "REPLACED", return -9999
var status_changed_to_replaced = $feature.Status == "REPLACED" &amp;amp;&amp;amp; $originalfeature.Status != "REPLACED"
if(!status_changed_to_replaced) { return -9999 }

// copy attributes
var copy_fields = ["Field1", "Field2", "Field3"]  // exclude readonly fields (OBJECTID, GlobalID, editor tracking, etc.)
var old_attributes = Dictionary(Text($feature)).attributes
var new_attributes = Dictionary()
for(var f in copy_fields) {
    var field = copy_fields[f]
    new_attributes[field] = old_attributes[field]
}
// optional: set attributes
new_attributes.Status = "AUTO_INSERTED"

// return the updated field value and instruct ArcGIS to create a new feature
return {
    "result": 2022,
    "edit": [{
        "className": "Database.DataOwner.Featureclass", // complete name of your feature class here (the same class as the one on which you create this rule)
        "adds": [{"geometry": Geometry($feature), "attributes": new_attributes}]
    }]
}&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 21 Jul 2022 08:50:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-to-create-new-feature-copy/m-p/1194346#M475</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-07-21T08:50:41Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation rule to create new feature (copy selected feature)</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-to-create-new-feature-copy/m-p/1194639#M478</link>
      <description>&lt;P&gt;Thanks so much Johannes.&amp;nbsp; I had lost hope.&amp;nbsp; I'll give this a try and will report back.&lt;/P&gt;&lt;P&gt;Thank you!!&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2022 20:22:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-to-create-new-feature-copy/m-p/1194639#M478</guid>
      <dc:creator>AndrewKan</dc:creator>
      <dc:date>2022-07-21T20:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation rule to create new feature (copy selected feature)</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-to-create-new-feature-copy/m-p/1196898#M485</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/294341"&gt;@JohannesLindner&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;This works great.&amp;nbsp; I was wondering tho if you can help me make a couple enhancements.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since I wanted to use this attribute rule for multiple feature classes I'm trying to figure out how to extract the feature class associated with the $feature instead of hardcoding it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, if possible it would be nice if I didn't have to hardcode the fields to copy since there are quite a few fields and if there's a schema change then I'd have to update the attribute rule also.&amp;nbsp; Ideally, it would be able to extract all the non-readonly fields and dump them into the copy_fields variable.&lt;/P&gt;&lt;P&gt;Thank you so much for your help thus far.&amp;nbsp; You're awesome.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 17:04:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-to-create-new-feature-copy/m-p/1196898#M485</guid>
      <dc:creator>AndrewKan</dc:creator>
      <dc:date>2022-07-28T17:04:54Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation rule to create new feature (copy selected feature)</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-to-create-new-feature-copy/m-p/1197281#M488</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;I'm trying to figure out how to extract the feature class associated with the $feature instead of hardcoding it.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;AFAIK, that's not possible. You'll have to hardcode that.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;Ideally, it would be able to extract all the non-readonly fields and dump them into the copy_fields variable.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;That does sound like a better way... You'll have to hardcode the readonly fields, but they should be the same for all feature classes, so you only have to do it once. The list in the code is not complete!&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var readonly_fields = ["OBJECTID", "GlobalID", "Shape__Area", "Shape__Length", "created_by", "created_on", "GDB_ARCHIVE_OID", "GDB_IS_DELETE"]  // exclude readonly fields (OBJECTID, GlobalID, editor tracking, versioning, etc.)
var old_attributes = Dictionary(Text($feature)).attributes
var new_attributes = Dictionary()
for(var field in old_attributes) {
    if(!Includes(readonly_fields, field)) {
        new_attributes[field] = old_attributes[field]
    }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 29 Jul 2022 09:51:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-to-create-new-feature-copy/m-p/1197281#M488</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-07-29T09:51:22Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation rule to create new feature (copy selected feature)</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-to-create-new-feature-copy/m-p/1197439#M490</link>
      <description>&lt;P&gt;This works great!&amp;nbsp; Thanks again for all your help.&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jul 2022 16:18:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-to-create-new-feature-copy/m-p/1197439#M490</guid>
      <dc:creator>AndrewKan</dc:creator>
      <dc:date>2022-07-29T16:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation rule to create new feature (copy selected feature)</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-to-create-new-feature-copy/m-p/1386331#M1303</link>
      <description>&lt;P&gt;Hello Johannes,&lt;/P&gt;&lt;P&gt;I have been attempting this expression for a similar workflow but have been consistently running into a "Geometry cannot have Z values" error. The feature class I am copying from is Z-enabled while the feature class I am copying to is not. Do you know how I can resolve this issue? Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2024 21:48:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculation-rule-to-create-new-feature-copy/m-p/1386331#M1303</guid>
      <dc:creator>BrianRosa</dc:creator>
      <dc:date>2024-02-23T21:48:34Z</dc:date>
    </item>
  </channel>
</rss>

