Constraint Rule to Prevent Deleting of Features

688
6
Jump to solution
08-12-2021 07:24 AM
ChrisGAEG
Occasional Contributor

Hello, I am trying to write a rule that will prevent the deletion of features in an fc. I'm getting the error 'Invalid expression. Close parenthesis expected' but I don't know why. Here is what I have so far. 

var currentAssetId = $feature.cab_id
var fsMyClass = FeatureSetByName($datastore, "Proposed_OLT_LCP_Boundaries_copy")
var fsResult = filter(fsMyClass, "cab_id = @currentAssetId")

if (first(fsResult) IN $originalfeature.cab_id)

return true;
else
return false; 

I believe the problem is in the if statement but I don't know what would be wrong here. 

0 Kudos
1 Solution

Accepted Solutions
HusseinNasser2
Esri Contributor

The if statement is an invalid syntax. You are comparing a feature (first(fsResult)) to a value $originalfeature.cab_id. Plus don't use IN, use == instead and compare the actual values 

 

That being said, I'm not sure what the rule is trying to do, maybe provide a brief description of what the rule is suppose to do? Going by your statement if you want to prevent deletion of features it is a matter of simply creating a constraint rule that returns false.  

 

return false;

 

 

View solution in original post

6 Replies
JoeBorgione
MVP Esteemed Contributor

Just a shot in the dark, but don't you need to enclose things in curly braces?

 

if (first(fsResult) IN $originalfeature.cab_id){
    return true;
}else{
    return false; 
}
That should just about do it....
0 Kudos
ChrisGAEG
Occasional Contributor

I tried this while troubleshooting before posting, but unfortunately this doesn't clear the error. Thanks for taking a look. 

JoeBorgione
MVP Esteemed Contributor

Rats...

That should just about do it....
0 Kudos
HusseinNasser2
Esri Contributor

The if statement is an invalid syntax. You are comparing a feature (first(fsResult)) to a value $originalfeature.cab_id. Plus don't use IN, use == instead and compare the actual values 

 

That being said, I'm not sure what the rule is trying to do, maybe provide a brief description of what the rule is suppose to do? Going by your statement if you want to prevent deletion of features it is a matter of simply creating a constraint rule that returns false.  

 

return false;

 

 

JoeBorgione
MVP Esteemed Contributor

Good catch...

That should just about do it....
ChrisGAEG
Occasional Contributor

Wow so simple, that's great. Thanks again!

0 Kudos