Select to view content in your preferred language

Edit Log to capture Insert, Update, and Deletes via ArcGIS Arcade attribute rule

629
11
Jump to solution
07-31-2024 11:15 AM
tbearb
by
Regular Contributor

I attended the Esri UC this year and this arcade expression was shown as an attribute rule in ArcGIS Pro that captures the audit history of a particular feature class / field(s), regarding the Insert, Update, and Delete event triggers. The script works great for capturing attribute changes, but as soon as you try to incorporate geometry changes, we see errors.

To only test the "Insert" event, I added the following lines:

var featureGeometry = null;

featureGeometry = $feature (within the insert event)

'geometry' : featureGeometry (added to the returned dictionary)

Can anyone point out what can be wrong with this arcade expression being used in an attribute rule in ArcGIS Pro? At the moment when I try to create a new point feature, I receive an 'Invalid geometry' error

// User variables
var current_edit = "NONE";
var featureGeometry = null; 

// User-editable fields
var fieldsArray = ['comments'];
var arrayLength = Count(fieldsArray);

// Process edit

// If a new feature was added
if ($editcontext.editType == 'INSERT') {
  current_edit = 'NEW FEATURE ';
  featureGeometry = $feature;
}

// If an existing feature was updated
if ($editcontext.editType == 'UPDATE') {
  current_edit = 'UPDATED FEATURE ';

  // if the geometries are not the same, record geometry update
  if ( !Equals( $originalFeature, $feature )){
      current_edit = current_edit + " Geometry update";
      
  }

  // check for changes in attribute values, record original value if changed
  for (var i = 0; i < arrayLength; i++) {
    if ($originalFeature[fieldsArray[i]] != $feature[fieldsArray[i]]) {
      // geometryEditOnly = false;
      current_edit = current_edit + ' {' + fieldsArray[i] + ': ' + $originalFeature[fieldsArray[i]] + '}';
    }
  }
}

// If an existing feature was deleted
if ($editcontext.editType == 'DELETE') {
  current_edit = 'DELETED FEATURE ';
  featureGeometry = $feature; 

  for (var i = 0; i < arrayLength; i++) {
    current_edit = current_edit + '{' + fieldsArray[i] + ': ' + $feature[fieldsArray[i]] + '} ';
  }
}

return {
  edit: [{
      'className': 'DBO.TestPointEdit',
      'adds': [{
          'attributes': {
            'edit_date': $feature.last_edited_date,
            'edit_feature': $feature.GlobalID,
            'editor': $feature.last_edited_user,
            'edit_action': $editcontext.editType,
            'edit_log': current_edit
          },
          'geometry' : featureGeometry      
        }
      ]
    }
  ]
};

tbearb_0-1722449680460.png

 

11 Replies
ZachBodenner
MVP Regular Contributor

Love the easy ones!

0 Kudos
Bud
by
Esteemed Contributor

Somewhat related: 
ArcGIS Pro Question: Track Changes in Point Feature Class with Records

0 Kudos