Select to view content in your preferred language

How to assign value to field using Arcade calculated value

2232
7
Jump to solution
04-16-2023 05:46 PM
OliverIshmael
Occasional Contributor

I wish to pre-populate the a field (Survey_Type) in my form with a Domain value "Asset" and have been attempting to do this using an Arcade expression. The expression returns false, and the value isn't added:

$feature.Survey_Type == "Asset"

 

What am i doing wrong?

0 Kudos
1 Solution

Accepted Solutions
JustinReynolds
Regular Contributor

You can not assign a value to a field in this way. $feature.[any field name] is a constant during the execution of any expression.  All you need to do is return the string "Asset". 

In designer, select the field Survey_Type. Then add a field calculation. 

 

return "Asset"

 


Here is some helpful documentation. 
https://developers.arcgis.com/arcade/guide/variables/

https://developers.arcgis.com/arcade/guide/return/

- Justin Reynolds, PE

View solution in original post

7 Replies
JeffSilberberg
Occasional Contributor III

 

Two equal signs is a comparison -- One equal is an assignment 

If you want to assign the vale then I think you want -- $feature.Survey_Type = "Asset"

0 Kudos
OliverIshmael
Occasional Contributor

Unfortunately, I already tried that. In red text Field Maps form says:

'Failed to calculate'

[ARCADE] - Expression failed to evaluate: \nName: expr/survey-type--asset\nError:java.util.concurrent.ExecutionException:com.esriarcgisruntime.ArcGISRuntimeException:Arcade expression is invalid.: Arcade evaluation error. Evaluation_error_code::cannot_assign_to_const_value Line:1

0 Kudos
JustinReynolds
Regular Contributor

You can not assign a value to a field in this way. $feature.[any field name] is a constant during the execution of any expression.  All you need to do is return the string "Asset". 

In designer, select the field Survey_Type. Then add a field calculation. 

 

return "Asset"

 


Here is some helpful documentation. 
https://developers.arcgis.com/arcade/guide/variables/

https://developers.arcgis.com/arcade/guide/return/

- Justin Reynolds, PE
RhettZufelt
MVP Notable Contributor

You might need to return the Domain Code and not the value.

You could also just set "Asset" as the default value in the template.

R_

0 Kudos
OliverIshmael
Occasional Contributor

@JustinReynolds @RhettZufelt I tried both of your suggestions (using calculated values, or, using default value) but neither of them result in a value being added to the field. The form completes successfully, but when i view the feature layer data no value has been saved for that field.

Do you know why this might be?

0 Kudos
JustinReynolds
Regular Contributor

Can you provide more details, I'd prefer not guess.

Please post your expressions in a JavaScript code block or screenshot it. Screenshot the Form as it is being completed, the popup afterword and the feature layer data you say is not being populated.

A screenshot of the field with its domain values would also be helpful.

Also, when you create the expression does it work when you test it in Field Maps Designer?

- Justin Reynolds, PE
0 Kudos
OliverIshmael
Occasional Contributor

Thank you for offering to help. Bizarrely it wasn't working yesterday but it is now. So that's good...i think?! 

0 Kudos