Validation Rule to Flag Duplicate Values

1777
7
Jump to solution
08-11-2021 01:13 PM
ChrisGAEG
Occasional Contributor

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. 

Tags (2)
0 Kudos
2 Solutions

Accepted Solutions
HusseinNasser2
Esri Contributor
 //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

View solution in original post

0 Kudos
ChrisGAEG
Occasional Contributor

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?

View solution in original post

0 Kudos
7 Replies
HusseinNasser2
Esri Contributor
 //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

0 Kudos
ChrisGAEG
Occasional Contributor

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?

0 Kudos
HusseinNasser2
Esri Contributor

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. 

0 Kudos
ChrisGAEG
Occasional Contributor

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). 

0 Kudos
ChrisGAEG
Occasional Contributor

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. 

0 Kudos
ChrisGAEG
Occasional Contributor

Hi Hussein, I have one more question concerning this. How would this code change if made a constraint rule? Would it be drastically different? 

0 Kudos
HusseinNasser2
Esri Contributor

It should be identical 

0 Kudos