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.
Here is what the Municipality_Codes domain looks like:
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;
Solved! Go to Solution.
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;
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;