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.
Solved! Go to Solution.
//detect duplicate
var currentAssetId = $feature.assetId
var currentObjectId = $feature.objectid
var 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 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
A bit slow but should work.
Alternatively you can do a summary statistics on the class and detect where count > 1
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 duplicate
var currentAssetId = $feature.assetId
var currentObjectId = $feature.objectid
var 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 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
A bit slow but should work.
Alternatively you can do a summary statistics on the class and detect where count > 1
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?
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.
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).
Scratch that, I think I figured that part out. I will play with it a bit and see if I can get the rest. Thank you for your help so far.
Hi Hussein, I have one more question concerning this. How would this code change if made a constraint rule? Would it be drastically different?
It should be identical