Select to view content in your preferred language

Arcade Constraint Rule: Update a date field with Today() if any field except fieldA and fieldB are modified

214
0
05-30-2024 08:46 AM
WilliamZoeller1
New Contributor

I am trying to create an attribute constraint rule that will populate a date field with current date if any of the fields of a feature class are updated except if the field is either fieldX and fieldY

The following Arcade works such that if any field is modified the modified_date field is updated even if there are modifications to fieldX or fieldY. So therefore it does not seem to me that the script is honoring the conditional statement with the array of columns to exclude. 

 

// Define the columns to exclude

var excludeColumns = ["fieldX", "fieldY"];

 

// Initialize a flag to track if any relevant field is modified

var isModified = false;

 

// Loop through each field in the feature

for (var field in $feature) {

 

// Check if the field is not in the exclude list

if (indexOf(excludeColumns, field) == -1) {

 

// Check if the field has been modified

if (IsEmpty($originalFeature[field]) || $feature[field] != $originalFeature[field]) { isModified = true; break;

}

}

}

 

// If any relevant field is modified, update the "last_update" column with the current date

if (isModified) {

return { "result": Now()

};

}

 

// If no relevant field is modified, return null to indicate no change

return {

"result": $feature["last_update"]

};

0 Kudos
0 Replies