I am trying to create an attribute rule that validates if a street name is in a master street table when being created. Here is the code I have so far, I am not sure where my syntax is wrong.
The expression needs to be case in-sensitive, the source data in the master table is mixed casing.
Thanks in advance!
// 1. Access the reference table by name
// This must match the name of the layer in your database/service
var masterStreetName = Upper(FeatureSetByName($datastore, 'vwAddresserData_v2', ["FULLADDRESS"], false));
// 2. Get the address being entered/edited
var addresserStreetName = Upper($feature.FullStreetName);
// 3. Handle empty values (optional: allow or block nulls)
if (IsEmpty(addresserStreetName)) { return true; }
// 4. Filter the other table for matching addresses
// Use Upper() to ensure the comparison isn't case-sensitive
var filterSQL = "FULLADDRESS = '" + addresserStreetName + "'";
var matches = Filter(masterStreetName, '@filterSQL');
// 5. Logic: Return true if a match is found, false (with message) if not
if (Count(matches) > 0) {
return true;
} else {
return {
"errorMessage": "The address " + addresserStreetName + " does not exist in the master Street table."
};
}
How was the master street name table created? Is it registered with the GDB? Who is the owner of the table?
The master street table is a view. It is registered with the GDB and same owner as the addressData layer. I tried loading it as a standalone table in the GDB and sharing with the other layer in the service but that also did not work.
The table does not have to be in the service. I wonder if it has to deal with you do not have Exclude from Client Application checked. Try checking that so the rule is only run the database.
That worked! Thank you! I will try adding to a web application and see how that goes.
Thank you so much for you prompt replies I really appreciate it.