<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Attribute Lookup in Attribute Rules Questions</title>
    <link>https://community.esri.com/t5/attribute-rules-questions/attribute-lookup/m-p/1558535#M1618</link>
    <description>&lt;P&gt;The address solution has a constraint rule, you could adapt it to find the closets match to the input and fill out value:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;// This rule will ensure the full name exist in the Master Road Name table
// It will compare the left and right municipality to the municipality in the Master Road Name table
// If the left and right municipality are different there will need to be a road name for each municipality in the Master Road Name table

// Define the Road Centerline fields
var fullname_field = "fullname";
var munileft_field = "munileft";
var muniright_field = "muniright";

// Define the Master Road Names fields
var masterfullname_field = "fullname";
var mastermuni_field = "municipality";

// If the fullname is blank or null return
If (!HasKey($feature, fullname_field)) return true;
var fullname = $feature[fullname_field];
If (IsEmpty(fullname)) return true;

// Get the left and right side municipalities
var munileft = $feature[munileft_field];
var muniright = $feature[muniright_field];
var municipalities = [munileft, muniright];

// This function will attempt to find partial matches in the master road name table
function findPartialMatches(search_municipalities) {
    //Attempt to find partial matches and return in error message
    var partialMatches = [];
    var fullname_parts = Split(fullname, ' ', -1, true)
    var muni_clause = mastermuni_field + " IN @search_municipalities"
    if (Includes(search_municipalities, null)) {
        muni_clause = "(" + mastermuni_field + " IS NULL OR " + mastermuni_field + " IN @search_municipalities)"
    }
    
    for (var i in fullname_parts) {
        if (Count(fullname_parts[i]) &amp;lt; 3) continue;
        
        var search_string = "%" + fullname_parts[i] + "%";
        var masterRoadNames = Filter(FeatureSetByName($datastore, "MasterRoadName", [masterfullname_field, mastermuni_field], false), muni_clause + " AND " + masterfullname_field + " LIKE @search_string");
        for (var road in masterRoadNames) {
            var roadname = `${road[masterfullname_field]} (${road[mastermuni_field]})`
            if (!Includes(partialMatches, roadname)) {
                Push(partialMatches, roadname );
            }    
        }
    }
    
    return partialMatches;
}

// Search the master road name table for a row matching the fullname and municipality
var muni_clause = mastermuni_field + " IN @municipalities"
if (Includes(municipalities, null)) {
    muni_clause = "(" + mastermuni_field + " IS NULL OR " + mastermuni_field + " IN @municipalities)"
}
var masterRoadNames = Filter(FeatureSetByName($datastore, "MasterRoadName", [masterfullname_field, mastermuni_field], false), muni_clause + " AND " + masterfullname_field + " = @fullname");

// If the left and right side municipality we only need one matching record
// If no matching records are found return an error
if (munileft == muniright) {
    if (Count(masterRoadNames) == 0) {   
        //Attempt to find partial matches and return in error message
        var partialMatches = findPartialMatches(municipalities);
        if (Count(partialMatches) == 0) return {"errorMessage" : "Match for left and right municipality not found. No partial matches found." };
        return {"errorMessage" : "Match for left and right municipality not found. Partial matches: " + Concatenate(partialMatches, ", ")};
    }
}
// If left and right side municipality are different, we need one record for each municipality in the table
else {
    var leftmatch = null;
    var rightmatch = null;
    for (var road in masterRoadNames) {
        if (road[mastermuni_field] == munileft) leftmatch = `${road[masterfullname_field]} (${road[mastermuni_field]})`;
        if (road[mastermuni_field] == muniright) rightmatch = `${road[masterfullname_field]} (${road[mastermuni_field]})`;
    }
    
    // If either the left or the right side municipality is not found return an error
    if (IsEmpty(leftmatch) || IsEmpty(rightmatch)) {
        var error = "Match for left and right municipality not found. "
        var search_municipalities = municipalities;
        if (IsEmpty(leftmatch) &amp;amp;&amp;amp; !IsEmpty(rightmatch)) {
            error = "Match for left municipality not found. ";
            search_municipalities = [munileft];
        }
        if (!IsEmpty(leftmatch) &amp;amp;&amp;amp; IsEmpty(rightmatch)) {
            error = "Match for right municipality not found. ";
            search_municipalities = [muniright];
        }
        
        var partialMatches = findPartialMatches(search_municipalities);
        if (Count(partialMatches) == 0) return {"errorMessage" : error + "No partial matches found." };
        return {"errorMessage" : error + "Partial matches: " + Concatenate(partialMatches, ", ")};
    }
}
return true;&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 14 Nov 2024 10:45:07 GMT</pubDate>
    <dc:creator>MikeMillerGIS</dc:creator>
    <dc:date>2024-11-14T10:45:07Z</dc:date>
    <item>
      <title>Attribute Lookup</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/attribute-lookup/m-p/1556825#M1617</link>
      <description>&lt;P&gt;Attribute Assistant add-in in ArcMap used to have a "Validation Attribute Lookup" functionality were you could type in the first couple of characters and it would do a quick search against a table in the background and list a set of filtered choices top on a drop down to pick from. Something like an Autocomplete Dropdown control you would come across on the web.&lt;/P&gt;&lt;P&gt;I was not able to find an equivalent feature while setting up Attribute Rules in ArcGIS Pro. Is there something similar to the&amp;nbsp;"Validation Attribute Lookup" available or did ESRI just take that feature away?&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2024 15:44:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/attribute-lookup/m-p/1556825#M1617</guid>
      <dc:creator>lakshmanankrishnan</dc:creator>
      <dc:date>2024-11-08T15:44:43Z</dc:date>
    </item>
    <item>
      <title>Re: Attribute Lookup</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/attribute-lookup/m-p/1558535#M1618</link>
      <description>&lt;P&gt;The address solution has a constraint rule, you could adapt it to find the closets match to the input and fill out value:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;// This rule will ensure the full name exist in the Master Road Name table
// It will compare the left and right municipality to the municipality in the Master Road Name table
// If the left and right municipality are different there will need to be a road name for each municipality in the Master Road Name table

// Define the Road Centerline fields
var fullname_field = "fullname";
var munileft_field = "munileft";
var muniright_field = "muniright";

// Define the Master Road Names fields
var masterfullname_field = "fullname";
var mastermuni_field = "municipality";

// If the fullname is blank or null return
If (!HasKey($feature, fullname_field)) return true;
var fullname = $feature[fullname_field];
If (IsEmpty(fullname)) return true;

// Get the left and right side municipalities
var munileft = $feature[munileft_field];
var muniright = $feature[muniright_field];
var municipalities = [munileft, muniright];

// This function will attempt to find partial matches in the master road name table
function findPartialMatches(search_municipalities) {
    //Attempt to find partial matches and return in error message
    var partialMatches = [];
    var fullname_parts = Split(fullname, ' ', -1, true)
    var muni_clause = mastermuni_field + " IN @search_municipalities"
    if (Includes(search_municipalities, null)) {
        muni_clause = "(" + mastermuni_field + " IS NULL OR " + mastermuni_field + " IN @search_municipalities)"
    }
    
    for (var i in fullname_parts) {
        if (Count(fullname_parts[i]) &amp;lt; 3) continue;
        
        var search_string = "%" + fullname_parts[i] + "%";
        var masterRoadNames = Filter(FeatureSetByName($datastore, "MasterRoadName", [masterfullname_field, mastermuni_field], false), muni_clause + " AND " + masterfullname_field + " LIKE @search_string");
        for (var road in masterRoadNames) {
            var roadname = `${road[masterfullname_field]} (${road[mastermuni_field]})`
            if (!Includes(partialMatches, roadname)) {
                Push(partialMatches, roadname );
            }    
        }
    }
    
    return partialMatches;
}

// Search the master road name table for a row matching the fullname and municipality
var muni_clause = mastermuni_field + " IN @municipalities"
if (Includes(municipalities, null)) {
    muni_clause = "(" + mastermuni_field + " IS NULL OR " + mastermuni_field + " IN @municipalities)"
}
var masterRoadNames = Filter(FeatureSetByName($datastore, "MasterRoadName", [masterfullname_field, mastermuni_field], false), muni_clause + " AND " + masterfullname_field + " = @fullname");

// If the left and right side municipality we only need one matching record
// If no matching records are found return an error
if (munileft == muniright) {
    if (Count(masterRoadNames) == 0) {   
        //Attempt to find partial matches and return in error message
        var partialMatches = findPartialMatches(municipalities);
        if (Count(partialMatches) == 0) return {"errorMessage" : "Match for left and right municipality not found. No partial matches found." };
        return {"errorMessage" : "Match for left and right municipality not found. Partial matches: " + Concatenate(partialMatches, ", ")};
    }
}
// If left and right side municipality are different, we need one record for each municipality in the table
else {
    var leftmatch = null;
    var rightmatch = null;
    for (var road in masterRoadNames) {
        if (road[mastermuni_field] == munileft) leftmatch = `${road[masterfullname_field]} (${road[mastermuni_field]})`;
        if (road[mastermuni_field] == muniright) rightmatch = `${road[masterfullname_field]} (${road[mastermuni_field]})`;
    }
    
    // If either the left or the right side municipality is not found return an error
    if (IsEmpty(leftmatch) || IsEmpty(rightmatch)) {
        var error = "Match for left and right municipality not found. "
        var search_municipalities = municipalities;
        if (IsEmpty(leftmatch) &amp;amp;&amp;amp; !IsEmpty(rightmatch)) {
            error = "Match for left municipality not found. ";
            search_municipalities = [munileft];
        }
        if (!IsEmpty(leftmatch) &amp;amp;&amp;amp; IsEmpty(rightmatch)) {
            error = "Match for right municipality not found. ";
            search_municipalities = [muniright];
        }
        
        var partialMatches = findPartialMatches(search_municipalities);
        if (Count(partialMatches) == 0) return {"errorMessage" : error + "No partial matches found." };
        return {"errorMessage" : error + "Partial matches: " + Concatenate(partialMatches, ", ")};
    }
}
return true;&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 14 Nov 2024 10:45:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/attribute-lookup/m-p/1558535#M1618</guid>
      <dc:creator>MikeMillerGIS</dc:creator>
      <dc:date>2024-11-14T10:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: Attribute Lookup</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/attribute-lookup/m-p/1559296#M1625</link>
      <description>&lt;P&gt;I think this might help with what I am trying to do. Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2024 18:17:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/attribute-lookup/m-p/1559296#M1625</guid>
      <dc:creator>lakshmanankrishnan</dc:creator>
      <dc:date>2024-11-15T18:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: Attribute Lookup</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/attribute-lookup/m-p/1559340#M1627</link>
      <description>&lt;P&gt;I'm in the same situation. I opted for importing that MasterStreetName table as a .csv to create a Domain for that field.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2024 19:11:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/attribute-lookup/m-p/1559340#M1627</guid>
      <dc:creator>mlguanes</dc:creator>
      <dc:date>2024-11-15T19:11:35Z</dc:date>
    </item>
  </channel>
</rss>

