ADMS Update Site Addresses attribute rule not working

230
1
03-15-2024 08:18 AM
masslc
by
New Contributor II

I have Esri's ADMS solution set up to work with my own data and everything is firing off correctly aside from the Update Site Address rule that is linked to the road attribute rules. I call out the equivalent fields for our data in the variables in the original solution, and have the rules in the same order, although I do have some additional ones too. Here is the code:

 

// This rule will run when the road name changes, find all site addresses that fall within the address range and update their road name

// Define Road Centerline fields
var fullname_field = "fullname";
var fromleft_field = "fromaddr_l";
var fromright_field = "fromaddr_r";
var toleft_field = "toaddr_l";
var toright_field = "toaddr_r";
var munileft_field = "uninccom_l"; 
var muniright_field = "uninccom_r"; 

// Define the Site Addresses fields
var addressfullname_field = "fullname";
var addrnum_field = "housenumber";
var municipality_field = "municipality";

// If the full road name is unchanged return;
If (!HasKey($feature, fullname_field)) return;
var fullname = $feature[fullname_field];
var origFullName = $originalFeature[fullname_field]
if (origFullName == fullname) return;

var fromLeft = $feature[fromleft_field];
var toLeft = $feature[toleft_field];
var fromRight = $feature[fromright_field];
var toRight = $feature[toright_field];

// This function will return the parity (0-0, Even, Odd, Both) given the from and to values of a side
function getParity(from, to) {
    if (IsEmpty(from) || from == 0 || IsEmpty(to) || to == 0) {
  if (from == 0 && to == 0) {
   return ["0-0", 0, 0];
  }
  return ["Error", null, null];
 }
    var minval = Min([from, to]);
 var maxval = Max([from, to]);
 
    if (from % 2 == 0 && to % 2 == 0) return ["Even", minval, maxval];
    
    if (from % 2 != 0 && to % 2 != 0) return ["Odd", minval, maxval];
    
    return ["Both", minval, maxval];
}

function updateSiteAddress(updates, siteAddress) {
 Push(updates, {
  'globalID': siteAddress[globalid_field],
  'attributes': Dictionary(addressfullname_field, fullname)
 })
}

var parityLeft = getParity(fromLeft, toLeft);
var parityRight = getParity(fromRight, toRight);

// If the road has no odd or even ranges return
if (Includes(["0-0", "Error"], parityLeft[0]) && Includes(["0-0", "Error"], parityRight[0])) return;

// Find all site addresses that have the same road name as road name prior to the edit
// Add each matching site address to an array storing the global id and updated road name
var updates = []
var siteAddresses = Filter(FeatureSetByName($datastore, "egdb.data.SiteAddressPointsMSD", [addressfullname_field, addrnum_field, municipality_field, "globalid"], false), addressfullname_field + " = @origFullName");
var globalid_field = Schema(siteAddresses).globalIdField;
for (var siteAddress in siteAddresses) {
    // Test if the address number is a number, if not continue
    var addrnum = Number(siteAddress[addrnum_field])
    if (isNaN(addrnum)) {
        continue;
    }
    
 if (siteAddress[municipality_field] == $feature[munileft_field] && (addrnum >= parityLeft[1] && addrnum <= parityLeft[2])) {
  if (parityLeft[0] == "Both") {
   updateSiteAddress(updates, siteAddress);
  }
  else if (parityLeft[0] == "Odd" && addrnum % 2 != 0) {
   updateSiteAddress(updates, siteAddress);
  }
  else if (parityLeft[0] == "Even" && addrnum % 2 == 0) {
   updateSiteAddress(updates, siteAddress);
  }
 }
 
 if (siteAddress[municipality_field] == $feature[muniright_field] && (addrnum >= parityRight[1] && addrnum <= parityRight[2])) {
  if (parityRight[0] == "Both") {
   updateSiteAddress(updates, siteAddress);
  }
  else if (parityRight[0] == "Odd" && addrnum % 2 != 0) {
   updateSiteAddress(updates, siteAddress);
  }
  else if (parityRight[0] == "Even" && addrnum % 2 == 0) {
   updateSiteAddress(updates, siteAddress);
  }
 }
}

// Using the edit parameter return the list of updates for the site address points
return {
    'edit': [
        {'className': 'egdb.data.SiteAddressPointsMSD', 'updates': updates}
    ]
};

 

The Centerline munileft_field and muniright_field variables both reference the same data type as the Site Address municipality_field, with the same values. Each references the same domain.

When I insert a centerline that is included in the Master Road Name table, followed by an address point, everything works as it should. Then when I select the centerline and rename it in it's attributes to match another road in the Master Road Name table, I check the site address point after but it still reflects the old centerline name. 

Any ideas? Thanks!

1 Reply
TedHoward2
Esri Contributor

So you are not seeing any errors? A couple things you could check:

- Make sure rule is not disabled (happens to me all the time)

- Check values in addrnum_field are numbers only. Numbers as text is ok.

- Make sure Site Address number falls within from/to range on Centerline

- The rule may be exiting early. Try adding Expects statement at beginning of rule.

Expects($feature, "fullname", "fromaddr_l", "fromaddr_r", "toaddr_l", "toaddr_r", "uninccom_l", "uninccom_r")

 

0 Kudos