Arcade expression with multiple variables

867
4
Jump to solution
06-29-2021 04:01 AM
Sietse_de_Haan
New Contributor III

Hi there,

I am creating a map to perform inspections on several locations. These locations have different quality to be maintained at, "onderhoudskwaliteit". During the inspection, the quality will be noted in the survey, "kwaliteit_inspectie". There are several answers possible when there is no maintenance needed and vice versa. I have written these answers in the expression so the expression knows what to return. So far so good I believe.

The next step is, to check the inspection date when the expression returns 'Geen onderhoud'. When this is returned, the expression needs to return "Onderhoud in verschiet" after 14 days, and "Onderhoud uitvoeren" after 28 days.

Since I'm not that good yet at writing expressions I would like some help with this. So far I have written the expression shown below, but this one isn't working yet. Where am I making mistakes, or how would you guys write this expression?

Thank you in advanced!

var inspectie = $feature.kwaliteit_inspectie
var kwaliteit = $feature.onderhoudskwaliteit
var days = DateDiff(Now(), $feature.CreationDate, "days")

when(
kwaliteit "B" == "A+", "Geen onderhoud",
kwaliteit "B" == "A", "Geen onderhoud",
kwaliteit "B" == "B", "Geen onderhoud",
kwaliteit "B" == "C", "Onderhoud uitvoeren",
kwaliteit "B" == "D", "Onderhoud uitvoeren",
kwaliteit "C" == "A+", "Geen onderhoud",
kwaliteit "C" == "A", "Geen onderhoud",
kwaliteit "C" == "B", "Geen onderhoud",
kwaliteit "C" == "C", "Geen onderhoud",
kwaliteit "C" == "D", "Onderhoud uitvoeren"
)

when(
"Geen onderhoud"
if (days > 14) {
return "Onderhoud in verschiet";
}
if (days > 28) {
return "Onderhoud uitvoeren";
else {
return "Geen onderhoud";}

Sietse de Haan
https://www.linkedin.com/in/sietse-h-de-haan/
Tags(1)
0Kudos
1 Solution

Accepted Solutions
DavidPike
MVP频繁来讲ibutor
var inspectie = $feature.kwaliteit_inspectie var kwaliteit = $feature.onderhoudskwaliteit var days = DateDiff(Now(), $feature.CreationDate, "days") //function to assign numeric values to the letters function textValue(input) { if (input == 'D') { return 1 } if (input == 'C') { return 2 } if (input == 'B') { return 3 } if (input == 'A') { return 4 } if (input == 'A+') { return 5 } } //run the function against quality and inspection var inspectieNumber = textValue(inspectie) var kwaliteitNumber = textValue(kwaliteit) //if inspection >= quality, assign 'Geen 'etc... to qualityResult var qualityResult = '' if (inspectieNumber >= kwaliteitNumber) { qualityResult = "Geen onderhoud" } else { qualityResult = "Onderhoud uitvoeren" } var finalResult = qualityResult if (qualityResult == "Geen onderhoud" && days > 14) { finalResult = "Onderhoud in verschiet"; } if (qualityResult == "Geen onderhoud" && days > 28) { finalResult = "Onderhoud uitvoeren"; } return finalResult

View solution in original post

4 Replies
DavidPike
MVP频繁来讲ibutor
var inspectie = $feature.kwaliteit_inspectie var kwaliteit = $feature.onderhoudskwaliteit var days = DateDiff(Now(), $feature.CreationDate, "days") //function to assign numeric values to the letters function textValue(input) { if (input == 'D') { return 1 } if (input == 'C') { return 2 } if (input == 'B') { return 3 } if (input == 'A') { return 4 } if (input == 'A+') { return 5 } } //run the function against quality and inspection var inspectieNumber = textValue(inspectie) var kwaliteitNumber = textValue(kwaliteit) //if inspection >= quality, assign 'Geen 'etc... to qualityResult var qualityResult = '' if (inspectieNumber >= kwaliteitNumber) { qualityResult = "Geen onderhoud" } else { qualityResult = "Onderhoud uitvoeren" } var finalResult = qualityResult if (qualityResult == "Geen onderhoud" && days > 14) { finalResult = "Onderhoud in verschiet"; } if (qualityResult == "Geen onderhoud" && days > 28) { finalResult = "Onderhoud uitvoeren"; } return finalResult
jcarlson
MVP Honored Contributor

Great example of a custom function!

- Josh Carlson
Kendall County GIS
0Kudos
DavidPike
MVP频繁来讲ibutor

one forgetting that 'else if' exists! There must also be a less verbose way to assign the numbers to the letters?

0Kudos
Sietse_de_Haan
New Contributor III

You are my hero@DavidPikeIt works! Only thing is, that I cant apply any symbology yet since there are no inspetions done yet. But that will be fixed over time.

Also, I am learning from this again to build these kind of expressions. Thank you very much.:flexed_biceps:

Sietse de Haan
https://www.linkedin.com/in/sietse-h-de-haan/