Select to view content in your preferred language

Attribute Rule Refinement: Extract Characters from one field, compare coded domain and return domain description

168
1
Jump to solution
07-11-2025 06:36 AM
GrantCountyGISSup
Occasional Contributor

Hello

My goal with this rule is to get it to auto-populate our municipality field with a domain description when a user types in a parcel number.

I have assigned the Municipality_Codes domain to the Municipality field.

GrantCountyGISSup_0-1752240532712.png

Here is what the Municipality_Codes domain looks like:

GrantCountyGISSup_1-1752240679481.png

The first three numbers of the Parcel # coincides with the three numbers assigned to each municipality in the domain. 

Here is the the Arcade expression that I was able to come up with using ChatGPT.  It still does not work even if I try to use Calculate Field.  I feel like the first 12 lines make sense it's when it goes through the looping is where it is not working.

// 1. Validate PARCELNO & extract prefix
var src=$feature.PARCELNO;
if (IsEmpty(src) || Count(src) < 3) {
return null;
}
var prefix = Left(src, 3);

// 2. Get the full coded value domain object
var d = DomainName($feature, "Municipality");
if (d == null || d.type != "codedValue") {
return null;
}

// 3. Loop through codes
for (var cv of d.codedValues) {
var codeStr = Text(cv.code);
if (codeStr == prefix) {
// 4. Return the matching description
return cv.name;
}
}

return null;

 

 

0 Kudos
1 Solution

Accepted Solutions
GrantCountyGISSup
Occasional Contributor

I went at it with ChatGPT again, this time it gave me this expression and it worked.  Perhaps I just needed a fresh look at it.

var src=$feature.PARCELNO;
if (IsEmpty(src) || Count(src) < 3) {
  return null;
}
var prefix = Left(src, 3);

var d = Domain($feature, "Municipality");  // note: exact field name
if (d == null || d.type != "codedValue") {
  return null;
}

for (var cv of d.codedValues) {
  if (Left(Text(cv.code), 3) == prefix) {
    return cv.name;
  }
}

return null;

 

View solution in original post

0 Kudos
1 Reply
GrantCountyGISSup
Occasional Contributor

I went at it with ChatGPT again, this time it gave me this expression and it worked.  Perhaps I just needed a fresh look at it.

var src=$feature.PARCELNO;
if (IsEmpty(src) || Count(src) < 3) {
  return null;
}
var prefix = Left(src, 3);

var d = Domain($feature, "Municipality");  // note: exact field name
if (d == null || d.type != "codedValue") {
  return null;
}

for (var cv of d.codedValues) {
  if (Left(Text(cv.code), 3) == prefix) {
    return cv.name;
  }
}

return null;

 

0 Kudos