This is the expression that I have (written with the help of Microsoft Copilot).
All of these fields have domains but this returns null
// Define the fields you want to get the domain values for
var fields = ["util_point_type_ngas", "util_point_type_power", "util_point_type_water", "util_point_type_sswr", "util_point_type_strm", "util_point_type_telco"];
// Initialize an empty dictionary to store the domain values
var domainValues = {};
// Loop through each field and get its domain values
for (var i = 0; i < Count(fields); i++) {
var field = fields[i];
var mydomain = Domain($feature, field);
// Check if the field has a domain
if (!IsEmpty(mydomain)) {
var values = [];
for (var j = 0; j < Count(mydomain.codedValues); j++) {
values[j] = mydomain.codedValues[j].name;
}
domainValues[field] = values;
} else {
domainValues[field] = "No domain";
}
}
// Return the dictionary of domain values
return domainValues;