Is it possible to create a validation rule that will flag or warn when a duplicate value is being added in a new feature's attributes? I'm new to Arcade and have very limited Javascript experience. Any input or help on this is greatly appreciated.
Hi Hussein, thanks for you response. I applied the rule to a point fc, but nothing happens when I create a duplicate address. How do I get the flag to trigger? This is how I have the expression. I am testing locally and not on SDE database, before I apply to my orgs database.
//detect duplicate var currentAssetId = $feature.address var currentObjectId = $feature.OBJECTID var fsMyClass = FeatureSetByName($datastore, "Served_Address_copy") var fsResult = filter(fsMyClass, "address = @currentAssetId and OBJECTID <> @currentObjectId") // search for the same address but don't count the current row if (first(fsResult) == null) return true; //we did not find a duplicate else return false; //we did find a duplicate create an error feature
Are there any other steps I need to take to get this to trigger?
//detect duplicatevar currentAssetId = $feature.assetIdvar currentObjectId = $feature.objectidvar fsMyClass = FeatureSetByName($datastore, "myclass")var fsResult = filter(fsMyClass, "assetid = @currentAssetId and objectid <> @currentObjectId") // search for the same asset id but don't count the current rowif (first(fsResult) == null)return true; //we did not find a duplicate elsereturn false; //we did find a duplicate create an error feature
A bit slow but should work.
Alternatively you can do a summary statistics on the class and detect where count > 1
Hi Hussein, I have one more question concerning this. How would this code change if made a constraint rule? Would it be drastically different?
After creating the rule, I open the error inspector and when I click on the map (or the layer with the attribution rule) nothing comes up on error inspector. Is there something I'm missing? (I am on an advanced license).
Yes you will need to use the error inspector to trigger the validation rules. That will create an error feature showing you where the duplicates are
watch this youtube video where I show how to create and evaluate. Note that you can run validation rules and batch calculation rules on filegdb.
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.