Select to view content in your preferred language

Arcade help with calculated value in Field Maps

400
7
Jump to solution
03-25-2025 06:30 AM
peterverwey_ses
Occasional Contributor

Hi all,

I am looking for some help with a calculated value in Field Maps. My very limited Arcade is letting me down and any help would be appreciated.

Background

  • Using Field Maps for Damage Assessment
  • Feature is DamageAssessment
  • Need to calculate IsHabitable field - values are Habitable, Not Habitable, and Not Applicable
  • Other factors are BuildingType and Damage

Form order sees the following:

  • Select BuildingType
    •  options are Residential and a range of other values
  • Select Damage
    • options are None, Slight, Moderate, Severe and Destroyed
  • Calculate IsHabitable - this is where I need help

Rules:

  • For all BuildingType !== Residential, IsHabitable = Not Applicable
  • Where BuildingType == Residential
    • Where Damage == Severe || Damage == Destroyed, IsHabitable = Not Habitable
    • For all other Damage values, IsHabitable = Habitable

The form element for IsHabitable has conditional visibility for BuildingType == Residential

Questions:

  1. What Arcade code can I use to calculate the result I need according to the above rules? 
  2. This is a required field. If I have conditional visibility, will the calculation run if the condition is not met, or do I need to set a default value in the templates with IsHabitable Not Applicable?

The calculated value has conditional Editing allowed with a switch value so users can override the calculation.

0 Kudos
1 Solution

Accepted Solutions
AustinAverill
Frequent Contributor

Here is an example. For this, I start with single conditions and return the function based on that. If it doesn't meet the logic of the if statement it passes to the next logic. Finally if all non-applicable or non-habitable conditions are passed, it return habitable.

//handles non-residential buildings and returns not applicable
if($feature.BuildingType != 'Residential'){
    return 'Not Applicable'
};

//if it is "Residential" will check for damage and return val
if($feature.Damaga == 'Severe' || $feature.Damage == 'Destroyed'){
    return 'Not Habitable'
};

//if the building is residential and the damage is not severe or destroyed will return this vallue
return 'Habitable'

View solution in original post

7 Replies
AustinAverill
Frequent Contributor

Here is an example. For this, I start with single conditions and return the function based on that. If it doesn't meet the logic of the if statement it passes to the next logic. Finally if all non-applicable or non-habitable conditions are passed, it return habitable.

//handles non-residential buildings and returns not applicable
if($feature.BuildingType != 'Residential'){
    return 'Not Applicable'
};

//if it is "Residential" will check for damage and return val
if($feature.Damaga == 'Severe' || $feature.Damage == 'Destroyed'){
    return 'Not Habitable'
};

//if the building is residential and the damage is not severe or destroyed will return this vallue
return 'Habitable'
AustinAverill
Frequent Contributor

Misspelled "Damage" on line 6 and didn't catch it until after hitting post. 😥

0 Kudos
DougBrowning
MVP Esteemed Contributor

I would write it more traditional like this.  easier to follow.

 

if($feature.BuildingType != 'Residential'){
    //handles non-residential buildings and returns not applicable
    return 'Not Applicable'
}
else if($feature.Damaga == 'Severe' || $feature.Damage == 'Destroyed'){
    //if it is "Residential" will check for damage and return val
    return 'Not Habitable'
}
else {
    //if the building is residential and the damage is not severe or destroyed will return this vallue
    return 'Habitable'
}
peterverwey_ses
Occasional Contributor

@DougBrowning thank you. This is how I would think as well.

AustinAverill
Frequent Contributor

Adding the "else if" as statements is definitely probably more technically sound and has a better readable flow. I just didn't do it in my example to really flesh out each logic check as it's own entity for the sake of understanding how the code executes.

0 Kudos
peterverwey_ses
Occasional Contributor

@AustinAverill thank you so much for your help. 

Turns out I was completely over-thinking everything.

Not only that, I was using string values for an integer based domain. The working code is listed below. Thank you again. 

 

//handles non-residential buildings and returns not applicable
if($feature.Building_Type_General != 0) {
    return 9
};

//if it is "Residential" will check for damage and return val
if($feature.Damage == 4 || $feature.Damage == 5) {
    return 2
};

//if the building is residential and the damage is not severe or destroyed will return this value
return 1

 

0 Kudos
AustinAverill
Frequent Contributor

Ahh, yes. Forgetting something is on a integer coded domain will be a hinderance every time! 😂

0 Kudos