Im trying to create a constraint where if street_status=1 then the street_id must be null.
I tried this statement but I get an error message each time I try to update street_status or street_id
if ($feature.street_status==1 && $feature.street_id==null)
return true;
else
return false;
Thanks in advance!
Solved! Go to Solution.
Probably you missed the curly brackets when copying the code, but still:
if ($feature.street_status==1 && $feature.street_id==null) {
return true;
}
return false;
The problem with this code is the following: If you are inserting a street with street_status 2, it will return false, because you only check for street_status 1 and return false otherwise. This should work in those cases:
if ($feature.street_status==1 && $feature.street_id!=null) {
return false;
}
return true;
This defaults to returning true and only blocks the insert/edit on the combination you don't want.
Other things to check:
The constraint rule does the following: Only allow features to be edited/created when their status is 1 and the street_id is null. Any other value, fail the edit which is what you are experiencing.
You might want to define your logic more explicitly. I'm assuming you want to ONLY fail when the status is 1 AND the street_Id is not NULL.
You can specify your logic this way.
if ($feature.street_status==1 && $feature.street_id != null)
return false;
else
return true;
Hi there,
What error are you getting? Is street_status a numeric field?
Im getting the constraint popup when I change the street_status to any value.
Thanks!
Probably you missed the curly brackets when copying the code, but still:
if ($feature.street_status==1 && $feature.street_id==null) {
return true;
}
return false;
The problem with this code is the following: If you are inserting a street with street_status 2, it will return false, because you only check for street_status 1 and return false otherwise. This should work in those cases:
if ($feature.street_status==1 && $feature.street_id!=null) {
return false;
}
return true;
This defaults to returning true and only blocks the insert/edit on the combination you don't want.
Other things to check:
Thanks for the help.
I didn't realized that street_status wasn't numeric.
The constraint rule does the following: Only allow features to be edited/created when their status is 1 and the street_id is null. Any other value, fail the edit which is what you are experiencing.
You might want to define your logic more explicitly. I'm assuming you want to ONLY fail when the status is 1 AND the street_Id is not NULL.
You can specify your logic this way.
if ($feature.street_status==1 && $feature.street_id != null)
return false;
else
return true;