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:
What am i doing wrong?
Solved! Go to Solution.
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/
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"
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
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/
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_
@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?
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?
Thank you for offering to help. Bizarrely it wasn't working yesterday but it is now. So that's good...i think?!