<?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: Help using attribute rules to copy/paste a row from one feature class to another on change in Attribute Rules Questions</title>
    <link>https://community.esri.com/t5/attribute-rules-questions/help-using-attribute-rules-to-copy-paste-a-row/m-p/1370598#M1248</link>
    <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/188597"&gt;@MikeMillerGIS&lt;/a&gt;&amp;nbsp;I will need to look at this. We are not using UN at this time so I will probably have to do some finagling. I appreciate the help.&lt;/P&gt;</description>
    <pubDate>Tue, 16 Jan 2024 17:27:10 GMT</pubDate>
    <dc:creator>VanessaSimps</dc:creator>
    <dc:date>2024-01-16T17:27:10Z</dc:date>
    <item>
      <title>Help using attribute rules to copy/paste a row from one feature class to another on change</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/help-using-attribute-rules-to-copy-paste-a-row/m-p/1369104#M1238</link>
      <description>&lt;P&gt;Hello all- I am working to set up our attribute rules. I would like to create a rule that will copy/paste an edited row of a feature class to another feature class when there is a status change from active to inactive. this is an example of what I think the flow would look like:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="VanessaSimps_0-1704996641923.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/91277iF3DA722576F76C9E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="VanessaSimps_0-1704996641923.png" alt="VanessaSimps_0-1704996641923.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I did find a couple of examples where you can update a related table when a feature's attribute is changed, but haven't been able to find anything where I can trigger a copy/paste from one feature to another.&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;P&gt;&lt;STRONG&gt;Edit another feature class with a calculation rule.&lt;/STRONG&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var fsAddress = FeatureSetByName($datastore, "Address_pnts", ["globalid"], false)
var fsListAddpnts = Intersects(fsAddress, $feature)
var AddList = []
var counter = 0
var noAddress = Count(fsListAddpnts)
if (noAddress &amp;gt; 0) {
    for (var address in fsListAddpnts) {
        AddList[counter] = {
            'globalid': address.globalid,
            'attributes': {
                'add_district_name': $feature.DistrictName
            }
        }
        counter++
    }
    return {
        'result': noAddress + ' addresses found in the district.',
        'edit': [{
            'className': 'Address_pnts',
            'updates': AddList
        }]
    }
} else {
    return 'No address points in district.'
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;And this:&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;from &lt;A href="https://community.esri.com/t5/arcgis-pro-questions/attribute-rules-arcade-copying-feature-to-new/td-p/1229440" target="_self"&gt;this&lt;/A&gt; thread&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;return {
'edit': [{
'className': 'RetiredData',
'adds': [{
'attributes': {'ID': $feature.ID
},
'geometry': Geometry($feature)
}]
}]
}

//note ID is the name of a text attribute.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I feel like this second code block is close to what I want, but not sure if it will only work if I am using Utility Network? (we are not at this time).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2024 18:53:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/help-using-attribute-rules-to-copy-paste-a-row/m-p/1369104#M1238</guid>
      <dc:creator>VanessaSimps</dc:creator>
      <dc:date>2024-01-11T18:53:53Z</dc:date>
    </item>
    <item>
      <title>Re: Help using attribute rules to copy/paste a row from one feature class to another on change</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/help-using-attribute-rules-to-copy-paste-a-row/m-p/1369323#M1241</link>
      <description>&lt;P&gt;I found this &lt;A href="https://www.esri.com/arcgis-blog/products/arcgis-pro/data-management/advanced-gdb-attribute-rules-editing-external-features-with-attribute-rules/" target="_self"&gt;blog post&lt;/A&gt; and it is almost exactly what I want to do, but I do not need to use a buffer, I need to filter by attribute value.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2024 00:35:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/help-using-attribute-rules-to-copy-paste-a-row/m-p/1369323#M1241</guid>
      <dc:creator>VanessaSimps</dc:creator>
      <dc:date>2024-01-12T00:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: Help using attribute rules to copy/paste a row from one feature class to another on change</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/help-using-attribute-rules-to-copy-paste-a-row/m-p/1370022#M1243</link>
      <description>&lt;P&gt;We just finish a tool that creates an attribute that does exactly what you want.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Download the toolbox at the end of this post(Note only works with the UN at the moment, but the result AR could be made to work with non UN classes)&lt;/P&gt;&lt;P&gt;- Open Pro, navigate to the toolbox and expand Attribute Rules&lt;/P&gt;&lt;P&gt;- Open Create Abandon Classs&lt;/P&gt;&lt;P&gt;- Select the classes you wish to abandon/retire features from&lt;/P&gt;&lt;P&gt;- Specify the field and the value that will trigger the movement/abandonment&lt;/P&gt;&lt;P&gt;- This creates an AR on the selected classes and creates the class to copy the result to&lt;/P&gt;&lt;P&gt;- You cannot delete the updated feature, as the AR fires in the middle of an update edit, and deleting the features causes issue in the database&lt;/P&gt;&lt;P&gt;- We use a batch calculate AR on the abandon classes to delete the inactive rows in the source&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/Esri/Utility-Data-Management-Support-Tools/tree/Preview3.1.2" target="_blank" rel="noopener"&gt;https://github.com/Esri/Utility-Data-Management-Support-Tools/tree/Preview3.1.2&lt;/A&gt;&lt;/P&gt;&lt;DIV class=""&gt;&lt;A title="UtilityDataManagementSupport.atbx" href="https://github.com/Esri/Utility-Data-Management-Support-Tools/blob/Preview3.1.2/UtilityDataManagementSupport.atbx" target="_blank" rel="noopener"&gt;UtilityDataManagementSupport.atbx&lt;/A&gt;&lt;/DIV&gt;&lt;H3&gt;&amp;nbsp;&lt;/H3&gt;</description>
      <pubDate>Sun, 14 Jan 2024 18:12:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/help-using-attribute-rules-to-copy-paste-a-row/m-p/1370022#M1243</guid>
      <dc:creator>MikeMillerGIS</dc:creator>
      <dc:date>2024-01-14T18:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: Help using attribute rules to copy/paste a row from one feature class to another on change</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/help-using-attribute-rules-to-copy-paste-a-row/m-p/1370598#M1248</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/188597"&gt;@MikeMillerGIS&lt;/a&gt;&amp;nbsp;I will need to look at this. We are not using UN at this time so I will probably have to do some finagling. I appreciate the help.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2024 17:27:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/help-using-attribute-rules-to-copy-paste-a-row/m-p/1370598#M1248</guid>
      <dc:creator>VanessaSimps</dc:creator>
      <dc:date>2024-01-16T17:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: Help using attribute rules to copy/paste a row from one feature class to another on change</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/help-using-attribute-rules-to-copy-paste-a-row/m-p/1370604#M1249</link>
      <description>&lt;P&gt;Here is the code to copy the feature&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Expects($feature, '*');
var source_et_fields = ['created_user', 'created_date', 'last_edited_user', 'last_edited_date'];
var assoc_et_fields = ['CREATOR', 'CREATIONDATE', 'UPDATEDBY', 'LASTUPDATE'];
var system_prefix = 'orig';
var assoc_fs = FeatureSetByName($datastore, 'main.UN_6_Associations', ['*'], false);

// The field map defines the source to target fields, if this is an empty dict, it will be calculated on the fly
// for performance reasons, you may want to fill this out, but it would have to be maintained as you update your schema
// This code can generate the static field map and display it in the console;
var source_target_field_map = {};
var assoc_field_map = {};

// Feature must be out of service and abandoned
var process_when = {'Lifecyclestatus': [0]};

// Once a feature is abandon, we only want to add an abandon row if the values that we are monitoring changed.
var one_field_did_change = False;
for (var field in process_when) {
    var field_valid = false;
    for (var i in process_when[field]) {
        var val = process_when[field][i];
        if (val == null &amp;amp;&amp;amp; IsEmpty($feature[field]) ) {
            if ($originalFeature[field] != $feature[field]){
               one_field_did_change = true;
            }
            field_valid = true;
            break;
        } else if ($feature[field] == val || Text($feature[field]) == val) {
            if ($originalFeature[field] != $feature[field]){
               one_field_did_change = true;
            }
            field_valid = true;
            break;
        }
    }
    if (!field_valid){
        return
    }
}
if (!one_field_did_change){
   return
}

function IsEmptyButBetter(data) {
    if (IsEmpty(data)) return true;
    for (var x in data) return false;
    return true;
}

function build_field_map(source_schema, target_schema, system_fields, system_field_map_prefix) {
    console('Field Map');
    console('------------------------------------');
    var source_lookup = [];
    var target_lookup = [];
    var field_map_local = {};

    var source_fields = source_schema['fields'];
    // Add the GlobalID and ObjectID fields to the list of ET fields for all the system fields
    var local_source_et_fields = [];
    for (var i in system_fields) {
        Push(local_source_et_fields, Lower(system_fields[i]));
    }
    Push(local_source_et_fields, Lower(source_schema['objectIdField']));
    Push(local_source_et_fields, Lower(source_schema['globalIdField']));

    for (var i in source_fields) {
        var field_info = source_fields[i];
        var field_name = Lower(field_info['name']);
        // Do not store the oid, globalid or ET info in the lookup, will be handled separately
        if (Includes(local_source_et_fields, field_name)) {
            continue;
        }
        Push(source_lookup, field_name);
    }

    var target_fields = target_schema['fields'];
    for (var i in target_fields) {
        var field_info = target_fields[i];
        // We cannot map input to non editable target fields, such as shape_length, validationstatus
        if (!field_info['editable']){
            continue
        }
        var field_name = Lower(field_info['name']);
        Push(target_lookup, field_name);
        if (Includes(source_lookup, field_name)) {
            console(`'${field_name}': '${field_name}',`);
            field_map_local[field_name] = field_name;
        }

    }
    if (system_field_map_prefix == '' || system_field_map_prefix == null) {
        console('End Field Map');
        console('------------------------------------');
        console(' ');
        return field_map_local;
    }
    for (var i in local_source_et_fields) {
        var field_name = local_source_et_fields[i];
        var target_field = Lower(`${system_field_map_prefix}_${field_name}`);
        if (Includes(target_lookup, target_field)) {
            console(`'${field_name}': '${target_field}',`);
            field_map_local[field_name] = target_field;
        }
    }
    console('End Field Map');
    console('------------------------------------');
    console(' ');
    return field_map_local;
}

// If the field map was not defined, use the schema to build a dict of source to target field
if (IsEmptyButBetter(source_target_field_map)) {
    var target_schema = Schema(FeatureSetByName($datastore, 'main.ABElectricDistributionDevice', ['*'], false));
    var source_schema = Schema($feature);
    source_target_field_map = build_field_map(source_schema, target_schema, source_et_fields, system_prefix);
}

if (IsEmptyButBetter(assoc_field_map)) {
    var target_schema = Schema(assoc_fs);
    var source_schema = Schema(FeatureSetByName($datastore, 'main.UN_6_Associations', ['*'], false));
    assoc_field_map = build_field_map(source_schema, target_schema, assoc_et_fields, system_prefix);
}

// Use the field map to copy the attributes from the current feature to the abandon layer
var target_atts = {};
for (var source_field in source_target_field_map) {
    target_atts[source_target_field_map[source_field]] = $feature[source_field];
}
// Create the return edits dict.  Add Geometry for FeatureClasses
var abandon_row = {"attributes": target_atts};
var geo = Geometry($feature);
if (!IsEmpty(geo)) {
    abandon_row['geometry'] = geo;
}

// Query the Association table to get all associations, use the field map to copy to copy the attributes from the current feature to the abandon layer
var feat_guid = $feature.globalid;
var filtered_fs = Filter(assoc_fs, 'FROMGLOBALID = @feat_guid or TOGLOBALID = @feat_guid');
// Loop over the associations, using the field map to create the list of adds
var assoc_rows = [];
for (var row in filtered_fs) {
    var assoc_atts = {};
    for (var assoc_field in assoc_field_map) {
        assoc_atts[assoc_field_map[assoc_field]] = row[assoc_field];
    }
    var assoc_row = {"attributes": assoc_atts};
    Push(assoc_rows, assoc_row);
}
var return_dict = {
    "edit": [{
        "className": 'main.ABElectricDistributionDevice',
        "adds": [abandon_row]
    }
    ]
};
if (Count(assoc_rows) &amp;gt; 0) {
    Push(return_dict['edit'],
        {
            "className": 'main.ABAssociations',
            "adds": assoc_rows
        });
}
return return_dict;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code on the abandon layer in a batch calc rule&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;if ($feature.AB_BYPASS != 0)
{
    return;
}
return {
    "result": 1,
    "edit": [{
            "className": "main.ElectricDistributionDevice",
            "deletes": [{
                    "objectID": $feature.ORIG_OBJECTID
                }
            ]
        }
    ]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2024 17:46:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/help-using-attribute-rules-to-copy-paste-a-row/m-p/1370604#M1249</guid>
      <dc:creator>MikeMillerGIS</dc:creator>
      <dc:date>2024-01-16T17:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: Help using attribute rules to copy/paste a row from one feature class to another on change</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/help-using-attribute-rules-to-copy-paste-a-row/m-p/1401652#M1367</link>
      <description>&lt;P&gt;I downloaded the toolbox, but I am not seeing the Attribute Rules toolbox? I looked through all the toolboxes and tools just to make sure I wasn't missing something?!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="VanessaSimps_0-1711568367695.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/99255i0366B72C72B94C54/image-size/medium?v=v2&amp;amp;px=400" role="button" title="VanessaSimps_0-1711568367695.png" alt="VanessaSimps_0-1711568367695.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your assistance on this one.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 19:43:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/help-using-attribute-rules-to-copy-paste-a-row/m-p/1401652#M1367</guid>
      <dc:creator>VanessaSimps</dc:creator>
      <dc:date>2024-03-27T19:43:52Z</dc:date>
    </item>
    <item>
      <title>Re: Help using attribute rules to copy/paste a row from one feature class to another on change</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/help-using-attribute-rules-to-copy-paste-a-row/m-p/1404543#M1375</link>
      <description>&lt;P&gt;We recently moved the tools to their own toolbox.&amp;nbsp; I will work on getting a copy posted for you to test out.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2024 13:15:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/help-using-attribute-rules-to-copy-paste-a-row/m-p/1404543#M1375</guid>
      <dc:creator>MikeMillerGIS</dc:creator>
      <dc:date>2024-04-02T13:15:34Z</dc:date>
    </item>
    <item>
      <title>Re: Help using attribute rules to copy/paste a row from one feature class to another on change</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/help-using-attribute-rules-to-copy-paste-a-row/m-p/1405440#M1380</link>
      <description>&lt;P&gt;Here is a copy of the toolbox with the abandon rows.&amp;nbsp; Can also start to test out some of the other templated rules.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/Esri/arcade-expressions/tree/master/attribute_assistant" target="_blank"&gt;https://github.com/Esri/arcade-expressions/tree/master/attribute_assistant&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2024 20:05:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/help-using-attribute-rules-to-copy-paste-a-row/m-p/1405440#M1380</guid>
      <dc:creator>MikeMillerGIS</dc:creator>
      <dc:date>2024-04-03T20:05:15Z</dc:date>
    </item>
  </channel>
</rss>

