Select to view content in your preferred language

Update information based upon variable in another field (Arcade)

303
4
Jump to solution
04-03-2024 03:18 AM
MattSully
New Contributor III

When we are surveying birds across the moorland we need for the steps to be few and trying to create less steps for the surveyors.  This means that we need for records to be updated automatically.

If a record contains one thing then it will auto populate another field.

We will be using calculated field and Arcade for the production of this.  Just need some guidance as to what text to put in.  Not sure if which Profile variables or functions to use.

Introducing new Arcade functions and an enhanced playground (esri.com)

Common calculated expressions for ArcGIS Field Maps (esri.com)
None of the above seems to give me any pointers.  

Appreciate a little help.

Many thanks

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

Arcade uses the Decode function instead of switch/case.

Decode($feature.Doing,
       'Singing', 'Possible Breeder',
       'Pair in suitable nesting habitat', 'Probable Breeder',
       'Observed in suitable nesting habitats', 'Probable Breeder',
       //rest of cases
       'Unknown'
     );

View solution in original post

4 Replies
MattSully
New Contributor III

I have used this code, in Arcade.

// Declare breed_status variable
var breed_status;

// Get the value from the original field
var originalValue = $feature.Doing;

// Determine breeding status based on original field value
switch (originalValue) {
case 'Singing':
breed_status = 'Possible Breeder';
break;
case 'Pair in suitable nesting habitat':
case 'Observed in suitable nesting habitats':
case 'Agitated behaviour':
case 'Holding permanent territory':
case 'Nest building or excavating':
case 'Visiting nest site':
breed_status = 'Probable Breeder';
break;
case 'Recently fledged young, or downy young':
case 'Family party':
case 'Adults carrying faecal sac or food for young':
case 'Nest containing eggs':
case 'Nest with young seen or heard':
breed_status = 'Confirmed Breeder';
break;
case 'Flying over':
breed_status = 'Non Breeding';
break;
default:
breed_status = 'Unknown';
}

// Return the determined breed_status
return breed_status;

The error thrown is this: Test execution error: Unexpected token '{'.. Verify test data.
Not sure what this means....
Thank you.

0 Kudos
KenBuja
MVP Esteemed Contributor

Arcade uses the Decode function instead of switch/case.

Decode($feature.Doing,
       'Singing', 'Possible Breeder',
       'Pair in suitable nesting habitat', 'Probable Breeder',
       'Observed in suitable nesting habitats', 'Probable Breeder',
       //rest of cases
       'Unknown'
     );
MattSully
New Contributor III

Final solution to the issue, thank you @KenBuja  was to use Decode.

// Declare breed_status variable
var breed_status;

// Get the value from the original field
var originalValue = $feature.Doing;

// Determine breeding status based on original field value using Decode() function
breed_status = Decode($feature.Doing,
'Singing', 'Possible Breeder',
'Pair in suitable nesting habitat', 'Probable Breeder',
'Observed in suitable nesting habitats', 'Probable Breeder',
'Agitated behaviour', 'Probable Breeder',
'Holding permanent territory', 'Probable Breeder',
'Nest building or excavating', 'Probable Breeder',
'Visiting nest site', 'Probable Breeder',
'Recently fledged young, or downy young', 'Confirmed Breeder',
'Family party', 'Confirmed Breeder',
'Adults carrying faecal sac or food for young', 'Confirmed Breeder',
'Nest containing eggs', 'Confirmed Breeder',
'Nest with young seen or heard', 'Confirmed Breeder',
'Flying over', 'Non Breeding',
'Unknown' // Default value
);

// Return the determined breed_status
return breed_status;

0 Kudos
KenBuja
MVP Esteemed Contributor

If this is your full code, then you don't need to declare the variables breed_status and originalStatus. The code in my reply utilizes an implicit return, since it's a single-line expression.

0 Kudos