Select to view content in your preferred language

Attribute Rule invalidating my Arcade expression, even though the Expression Builder stated it as valid?

1176
2
Jump to solution
11-28-2023 07:18 AM
SenadHodzic1
Occasional Contributor

Hello All,

I have an arcade expression that is being accepted and validated by the Expression Builder:

SenadHodzic1_0-1701183906734.png


However, when I try to save my attribute rule, it starts saving but then it cancels and I get a red box near my attribute rule and I get this error:

SenadHodzic1_1-1701183945081.png

The premise of arcade expression is that Uniformat_Code (which has a domain) will dictate the value input into Unit_of_Measure based on the mapping in the attribute rule. I am applying this attribute rule on Unit_of_Measure as two more fields will need to have their value dictated in a similar fashion. Below is my expression:

 

// Define the mapping between Uniformat_Code and Unit_of_Measure
var uomMapping = {
    "A101001": "LM Footprint",
    "A103001": "SM Footprint",
    "A202001": "LM Footprint",
    "B102004": "SM",
    "B103001": "SM Building",
    "B201005": "SM",
    "B201008": "SM",
    "B201021": "SM",
    "B201022": "SM",
    "B201023": "SM",
    "B201024": "SM",
    "B201025": "SM",
    "B201026": "SM",
    "B201028": "SM",
    "B201030": "SM",
    "B201031": "LM",
    "B201032": "SM",
    "B202001": "SM",
    "B202003": "SM",
    "B203001": "Each",
    "B203002": "Each",
    "B203008": "Each",
    "B203021": "Each",
    "B203022": "Each",
    "B203026": "Each",
    "B203028": "Each",
    "B203029": "Each",
    "B301002": "SM",
    "B301003": "SM",
    "B301005": "LM",
    "B301027": "SM",
    "B301028": "SM",
    "B301029": "SM",
    "B301034": "SM",
    "B301099": "Lump Sum",
    "B302001": "SM",
    "C101001": "SM Building",
    "C101006": "SM",
    "C101023": "SM",
    "C101024": "SM",
    "C101027": "Each",
    "C102001": "Each",
    "C102002": "Each",
    "C102006": "Each",
    "C102007": "Each",
    "C102024": "Each",
    "C102026": "Each",
    "C102099": "Lump Sum",
    "C103005": "Each",
    "C103009": "LM",
    "C103010": "LM",
    "C103026": "Each",
    "C103028": "Each",
    "C103099": "Lump Sum",
    "C201001": "Per Riser",
    "C201002": "Per Riser",
    "C201003": "SM",
    "C201027": "LM",
    "C301005": "SM Building",
    "C301007": "SM",
    "C301022": "SM",
    "C301023": "SM",
    "C301025": "SM",
    "C301026": "SM",
    "C301027": "SM",
    "C301028": "SM",
    "C302001": "SM",
    "C302003": "SM",
    "C302005": "SM",
    "C302007": "SM",
    "C302021": "SM",
    "C302022": "SM",
    "C302023": "SM",
    "C302024": "SM",
    "C302025": "SM",
    "C302027": "SM",
    "C302099": "Lump Sum",
    "C303003": "SM",
    "C303004": "SM",
    "C303005": "SM",
    "C303006": "SM",
    "C303007": "SM",
    "C303008": "SM",
    "C303011": "SM",
    "C303099": "Lump Sum",
    "D101002": "Each",
    "D101003": "Each",
    "D201001": "Each",
    "D201002": "Each",
    "D201003": "Each",
    "D201004": "Each",
    "D201006": "Each",
    "D201011": "Each",
    "D201012": "Each",
    "D201015": "Each",
    "D201016": "Each",
    "D201031": "Each",
    "D201033": "Each",
    "D201043": "Each",
    "D202001": "SM Building",
    "D202006": "Litre",
    "D202007": "Litre",
    "D202008": "Each",
    "D202009": "mm",
    "D202021": "Each",
    "D202035": "Litre",
    "D202037": "Each",
    "D202038": "Per Collector",
    "D202039": "MBH",
    "D202099": "Lump Sum",
    "D203001": "SM Building",
    "D203006": "Each",
    "D203007": "Each",
    "D204002": "SM Building",
    "D204005": "Each",
    "D204099": "Lump Sum",
    "D209005": "SM",
    "D209006": "Each",
    "D301002": "SM ",
    "D301012": "Litre",
    "D302002": "MBH",
    "D302003": "MBH",
    "D302004": "Each",
    "D302005": "Each",
    "D302031": "Each",
    "D302032": "MBH",
    "D302099": "Lump Sum",
    "D303002": "Tons",
    "D303011": "Tons",
    "D303021": "Tons",
    "D303031": "Tons",
    "D303041": "Each",
    "D303099": "Lump Sum",
    "D304001": "SM Building",
    "D304003": "SM Building",
    "D304005": "SM",
    "D304006": "SM Building",
    "D304007": "Each",
    "D304012": "SM",
    "D304021": "Each",
    "D304022": "Each",
    "D304025": "Each",
    "D304031": "Each",
    "D304032": "Each",
    "D304033": "Each",
    "D304034": "Each",
    "D304041": "Each",
    "D304042": "Each",
    "D304051": "Each",
    "D304052": "Each",
    "D304053": "Each",
    "D304062": "Each",
    "D305002": "Each",
    "D305003": "Each",
    "D305004": "LM",
    "D305005": "Each",
    "D305006": "kW",
    "D305007": "Each",
    "D305009": "Each",
    "D305011": "Each",
    "D305013": "LM",
    "D305021": "Each",
    "D305022": "Tons",
    "D305023": "Each",
    "D305031": "MBH",
    "D305032": "Each",
    "D305041": "Each",
    "D305042": "Each",
    "D305043": "Each",
    "D306002": "SM Building",
    "D306003": "SM Building",
    "D306006": "SM Building",
    "D306011": "SM",
    "D306099": "Lump Sum",
    "D401001": "SM Building",
    "D402001": "SM Building",
    "D409003": "Each",
    "D409005": "Each",
    "D501002": "Each",
    "D501003": "Each",
    "D501004": "kVA",
    "D501005": "Each",
    "D501007": "Section",
    "D501022": "Each",
    "D501024": "Each",
    "D501025": "Each",
    "D501031": "SM Building",
    "D501034": "Each",
    "D501035": "Each",
    "D501037": "Each",
    "D501040": "per HP",
    "D501041": "Each",
    "D501099": "Lump Sum",
    "D502001": "SM Building",
    "D502002": "SM Building",
    "D502003": "Each",
    "D502011": "SM",
    "D502021": "SM",
    "D502027": "Each",
    "D502028": "Each",
    "D502030": "LM",
    "D502041": "Each",
    "D502051": "Each",
    "D503001": "SM Building",
    "D503003": "Each",
    "D503004": "SM Building",
    "D503006": "SM Building",
    "D503008": "SM Building",
    "D503018": "SM Building",
    "D509002": "kVA",
    "D509003": "Each",
    "D509007": "kVA",
    "D509008": "kW",
    "D509022": "kVA",
    "D509031": "Each",
    "D509032": "Each",
    "D509033": "Each",
    "D509045": "LM",
    "E101001": "SM",
    "E101004": "SM",
    "E101005": "Each",
    "E101007": "Each",
    "E101008": "Each",
    "E101010": "Each",
    "E102008": "Each",
    "E102010": "Per Hose Connection",
    "E109001": "Each",
    "E109004": "Each",
    "E201001": "Each",
    "E201002": "Each",
    "E201008": "SM",
    "E201099": "Lump Sum",
    "F101001": "Each",
    "F103010": "Lump Sum",
    "F104001": "SM",
    "F104002": "SM",
    "F104003": "Each",
    "F104004": "MBH",
    "F104005": "Each",
    "F104006": "Each",
    "F104007": "Each",
    "F104008": "Each",
    "F104013": "Each",
    "F104016": "Each",
    "F104018": "Each",
    "F104021": "SM",
    "F104022": "SM",
    "F104023": "SM",
    "F104024": "LM",
    "F104025": "SM",
    "F104026": "Each",
    "F104027": "Litre",
    "F104028": "Each",
    "F104029": "Each",
    "F104030": "Each",
    "F104031": "Tons",
    "F104032": "Each",
    "F104033": "Each",
    "F104034": "Each",
    "F104036": "Each",
    "F104037": "Each",
    "F104039": "Each",
    "F104099": "Lump Sum",
    "G201005": "LM",
    "G201021": "SM",
    "G201025": "SM",
    "G202021": "SM",
    "G202022": "SM",
    "G202024": "SM",
    "G203021": "SM",
    "G203022": "SM",
    "G203024": "SM",
    "G203026": "Per Riser",
    "G203030": "SM",
    "G204007": "SM",
    "G204009": "LM",
    "G204021": "LM",
    "G204022": "LM",
    "G204027": "LM",
    "G204031": "SM",
    "G204032": "SM",
    "G204033": "SM",
    "G204034": "SM",
    "G204075": "Per seat",
    "G204086": "SM",
    "G204086": "SM",
    "G204096": "SM",
    "G205004": "SM",
    "G301002": "LM",
    "G302001": "LM",
    "G302013": "LM",
    "G303001": "LM",
    "G306004": "Litre",
    "G401011": "LM",
    "G401012": "LM",
    "G402011": "Each",
    "G409011": "Each"
};

// Get the Uniformat_Code value from the feature
var uniCode = $feature.Uniformat_Code;

// Look up the corresponding Unit_of_Measure value in the mapping
var uom = uomMapping[uniCode];

// If the Uniformat_Code value is found in the mapping, return the Unit_of_Measure value
// If not, return null or a default value
return iif(IsEmpty(uom), null, uom);

 

 
Anyone know what is going on? I've tried replacing [unicode] with [$feature["Uniformat_Code"]. I am just really not sure what is going on.

Any and all help is appreciated.

Kind Regards,

Senad

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

The validator only checks against a subset of features. It's possible to get a valid expression that fails further down the table when it hits some exception.

I think you're going to run into trouble assigning a variable to a potentially missing code. Try using an Iif function, along with the HasKey function to check for the key first.

 

return iif(
  HasKey(uomMapping, uniCode),
  uomMapping[uniCode],
  null
)

 

 https://developers.arcgis.com/arcade/function-reference/dictionary_functions/#haskey

Edit: That code snippet is meant to replace lines 306-310 of your posted expression.

- Josh Carlson
Kendall County GIS

View solution in original post

2 Replies
jcarlson
MVP Esteemed Contributor

The validator only checks against a subset of features. It's possible to get a valid expression that fails further down the table when it hits some exception.

I think you're going to run into trouble assigning a variable to a potentially missing code. Try using an Iif function, along with the HasKey function to check for the key first.

 

return iif(
  HasKey(uomMapping, uniCode),
  uomMapping[uniCode],
  null
)

 

 https://developers.arcgis.com/arcade/function-reference/dictionary_functions/#haskey

Edit: That code snippet is meant to replace lines 306-310 of your posted expression.

- Josh Carlson
Kendall County GIS
SenadHodzic1
Occasional Contributor

Thank you Josh!

That worked for me. I hadn't realized HasKey existed. I am not all too familiar with Arcade and really just scoured the internet for some help. 

It took me a bit to understand why exactly my code didn't work and what you meant by "Missing". As the Uniformat Code is a non-nullable, domain applied field, there could be no "missing" value. But by missing, you meant that the value does not exist in any of my  records. Therefore the attribute rule could not be applied, which is why the error was being flagged. That's how i interpreted it at least, let me know if that's incorrect. 

 

0 Kudos