Arcade expression

1394
5
Jump to solution
03-27-2023 01:06 PM
Labels (1)
SLouq
by MVP Regular Contributor
MVP Regular Contributor

How can I write this Code Block as an Arcade expression

SLouq_0-1679947544243.png

 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DanielMiranda2
Occasional Contributor

You are missing a couple of curly brackets. Each return statement needs to be enclosed by curly brackets. Also, you need to use a double equals sign when checking if something is equal to a value. A single equals sign is used for assigning variables.

if($feature.MAJOR_ST == 'Farm'){
   return "No"
} else {
   return "Yes"
}

 Refer to If - else | ArcGIS Arcade | ArcGIS Developers for info on if-else syntax.

Refer to Operators | ArcGIS Arcade | ArcGIS Developers for operators, which discusses = vs ==.

For straight forward if-else statements, arcade also has an IIF function, which can be a little easier to create:

IIF($feature.MAJOR_ST == "Farm", "No", "Yes")

Logical functions | ArcGIS Arcade | ArcGIS Developers

View solution in original post

0 Kudos
5 Replies
jcarlson
MVP Esteemed Contributor

https://developers.arcgis.com/arcade/ has all kinds of resources. Your question isn't very specific, though. Is there a particular part you're having trouble with?

Arcade follows many of the conventions of JavaScript, so familiarity with that will help.

// defining a function
function myExpression(some_param) {
    // do something here
    return 'some value'
}

// an if-else block
If (some_condition) {
    // do something
} else if (another condition) {
    // do something else
} else {
    // do this if nothing else worked
}
- Josh Carlson
Kendall County GIS
0 Kudos
SLouq
by MVP Regular Contributor
MVP Regular Contributor

I know just enough coding to stumble my way through an expression in VB. I have never used Arcade. I will try your link and see if I can find something. 

Thanks

0 Kudos
SLouq
by MVP Regular Contributor
MVP Regular Contributor

Hi,

I tried  looking for a solution in the link you provided but wasn't successful. What I am trying to do is write a simple Arcade expression to find all streets in my map with a Street type of Farm and return a value of "No" but if Street type is not = to Farm then return a value of "Yes". 

This is all I can come up with but it doesn't verify

SLouq_0-1680013103989.png

 

Can you help me with this?

0 Kudos
DanielMiranda2
Occasional Contributor

You are missing a couple of curly brackets. Each return statement needs to be enclosed by curly brackets. Also, you need to use a double equals sign when checking if something is equal to a value. A single equals sign is used for assigning variables.

if($feature.MAJOR_ST == 'Farm'){
   return "No"
} else {
   return "Yes"
}

 Refer to If - else | ArcGIS Arcade | ArcGIS Developers for info on if-else syntax.

Refer to Operators | ArcGIS Arcade | ArcGIS Developers for operators, which discusses = vs ==.

For straight forward if-else statements, arcade also has an IIF function, which can be a little easier to create:

IIF($feature.MAJOR_ST == "Farm", "No", "Yes")

Logical functions | ArcGIS Arcade | ArcGIS Developers

0 Kudos
SLouq
by MVP Regular Contributor
MVP Regular Contributor

That worked!

Thank you so much!