I've searched and searched but either couldn't figure out how to word my question or it hasn't been asked. Basically, is it possible to use AND or OR in an IF statement so I don't have to make a bunch of expressions? Especially useful when it comes to pop-ups.
Example (very generalized):
I want to display a pop-up that shows one of three things; A, AB, or None. Naturally I would think of it like a definition query,
= IIf($feature["OCC_ELUM"] == 0, " ", "A")
OR
= IIf($feature["OCC_ELUM"] == 1, " ", "AB")
OR
= IIf($feature["OCC_ELUM"] == 2, " ", "None")
But this isn't the case. Any help?
Solved! Go to Solution.
Hi Bryan,
Something like this might work:
if ( $feature["OCC_ELUM"] == 0) {
return "A"
}
else if ( $feature["OCC_ELUM"] == 1) {
return "AB"
}
else if ( $feature["OCC_ELUM"] == 2) {
return "None"
}
You can add in as many 'else if's as needed. If you needed, you could finish it with 'else' to catch any other values
if ( $feature["OCC_ELUM"] == 0) {
return "A"
}
else if ( $feature["OCC_ELUM"] == 1) {
return "AB"
}
else if ( $feature["OCC_ELUM"] == 2) {
return "None"
}
else {
return "No Values"
}
Carmel
Hi Bryan,
Something like this might work:
if ( $feature["OCC_ELUM"] == 0) {
return "A"
}
else if ( $feature["OCC_ELUM"] == 1) {
return "AB"
}
else if ( $feature["OCC_ELUM"] == 2) {
return "None"
}
You can add in as many 'else if's as needed. If you needed, you could finish it with 'else' to catch any other values
if ( $feature["OCC_ELUM"] == 0) {
return "A"
}
else if ( $feature["OCC_ELUM"] == 1) {
return "AB"
}
else if ( $feature["OCC_ELUM"] == 2) {
return "None"
}
else {
return "No Values"
}
Carmel
Or use Decode()
Decode($feature.OCC_ELUM,1,"AB",2,"None","No Values")
Hi, this article helped to solve a big problem and many thanks. How can we replace '_' that contains in values of a field with space?
Wali
Hi Sayed Wali ,
I you want to replace "_" by " " you can use the function Replace. Something like this:
var result = Replace(YourText, "_", " ");
The best way to use AND in Arcade is the following: "&&" input && between the expressions like the following example:
If (($feature.GlobalID != Null) && ($feature.TYPE == "Conduit")){
Return "CONDUIT::" + Upper(right(split($feature.GLOBALID,"-")[0],8))
}
The above is a script that looks at data from two fields and returns a unique ID for an element based on the entries of that Field.
How would this work if I have two different fields that can signify the same thing?
Here is what I am trying to show:
Smoked -
Smoke = True OR Connected to Sanitary = True
Smoked w/ Problems
Smoked with Problems = True OR No Show = True
Test Failed
(No Smoke = True AND (SmokeProblem <> Vacant Lot OR SmokeProblem <> Parking Lot)) OR Connected to Storm = True
Septic
Septic = True
Vacant/Parking Lot
SmokeProblem <> Vacant Lot OR SmokeProblem <> Parking Lot
//Smoked
if ( DomainName($feature,"test_type") == 'Smoke Test')
{
if ( DomainName($feature,"other_testresult")=='Connected to Sanitary')
{
return "Smoked"
}
}
//Septic
else if ( DomainName($feature,"test_type") == 'Septic System')
{
return "Septic"
}
//Smoked with Problems
else if ( DomainName($feature,"smoke_result") == 'Smoke with Problems')
{
if (DomainName($feature,"other_testresult")=='No Show')
{
return "Smoked with Problems"
}
}
//Test Failed
else if (DomainName($feature,"smoke_result")=='No Smoke')
{
if ( $feature["vacant_lot"] == 0)
{
if ( $feature["parking_lot"] == 0)
{
return "Test Failed"
}
}
}
//Vacant/Parking Lot
else if ( $feature["vacant_lot"] == 1)
{
if ( $feature["parking_lot"] == 1)
{
return "Vacant/Parking Lot"
}
}
else {
return "No Values"
}
Here is what I have come up with so far, but it is only returning "No Values" . I think this has to do with the fact that I am trying to get two different fields to = the same thing. Has anyone done this before that can help me out?
Thank you in advance,
Vanessa
There is a technical article on this subject in the Esri Knowledge Base: How To: Use multiple Arcade IF statements in ArcGIS Online
Use && for AND conditions, use || for OR conditions. For instance you can use an expression like this in Arcade (OR):
if ($feature.evaluation_type == "01" || isEmpty($feature.evaluation_type)) {
return 0;
}