Arcade with Project User Input

293
4
Jump to solution
04-04-2024 03:53 PM
FrankHerbert
New Contributor III

I'm trying to create an arcade expression based on the project user input value but I'm struggling to get it working.

 

I have a feature layer called Animals. The project user input allows the user to select one of the following:

Blue Dog, Red Dog, Green Dog, Blue Cat, Red Cat, Green Cat, Blue Frog, Red Frog, Green Frog. One of these values then populates the Project field.

I'm trying to create an arcade expresssion within the same Animals feature layer. The field containing the arcade expression is called Result.

If Project contains text 'Dog' then the Result value is Dog.

If Project contains text 'Cat' then the Result value is Cat.

If Project contains text 'Frog' then the Result value is Frog.

 

So far this what I've got but can't get it working:

 

var Project = $layer.Project;

if (Contains(Project, "Dog")) {
  return "Dog";
} else if (Contains(Project, "Cat")) {
  return "Cat";
} else if (Contains(Project, "Frog")) {
  return "Frog";
}
 
 
If anybody has any suggestion that would be awesome 🙂
1 Solution

Accepted Solutions
FrankHerbert
New Contributor III

With a bit of trial n error, I got it working using this:

var Project = $feature.Project;

if (Project == null) {
  return "Unknown";
} else if (Find("Dog", Project) > -1) {
  return "Dog";
} else if (Find("Cat", Project) > -1) {
  return "Cat";
} else if (Find("Frog", Project) > -1) {
  return "Frog";
} else {
  return "Unknown";
}

View solution in original post

4 Replies
JohnathanHasthorpe
Esri Regular Contributor
Hi Frank, make sure that you use $feature in order to get the project user input value for the captured feature. Then use Find to do the check.
 
 
var Project = $feature.Project;

 

if (Find("Dog", Project) > -1) {
  return "Dog";
} else if (Find("Cat",Project,) > -1) {
  return "Cat";
} else if (Find("Frog", Project) > -1) {
  return "Frog";
}
 
FrankHerbert
New Contributor III

Thanks Jonathan. My Project field is working as intended - populating with the project user input, but the arcade script isn't populating the Result field (where the script is located in QuickCapture)... It's Friday afternoon over here so i'm going to check this again on Monday morning with a fresh mind!! Thanks again for your time.

FrankHerbert
New Contributor III

With a bit of trial n error, I got it working using this:

var Project = $feature.Project;

if (Project == null) {
  return "Unknown";
} else if (Find("Dog", Project) > -1) {
  return "Dog";
} else if (Find("Cat", Project) > -1) {
  return "Cat";
} else if (Find("Frog", Project) > -1) {
  return "Frog";
} else {
  return "Unknown";
}