Select to view content in your preferred language

Calculated Default Values

5544
24
04-27-2022 07:02 AM
JustinReynolds
Regular Contributor

We are now implementing form calculations in Field Maps on several projects and these have been a big help... some bugs to work through, but overall pretty good so far.

By design, a form calculation renders the field un-editable from within the form. This leaves me wanting a little bit as I have use cases for a calculation that fires once and only once on insert/creation but allows the field to remain editable. Call this calculated default values. Separate from a database default value of the underlying feature service and those set in feature templates which are both examples of static default values.

The classic use case is a date field (not a system date field like editor tracking)...

On insert set the date to today. e.g. return Today(); or return Now();. However, allow the field to remain editable so that a user can make a change. 90% of the time the user would need Today's date and when this event fires the user can ignore the field, but in the event that they are recording an inspection/event that occurred yesterday, today, then allow the user to manipulate the date.

By design it could be a different category of a form's field capabilities.

Currently we have

  • Calculated Expressions
  • Conditional Visibility

Can an option be added for these types of cases? Calculated Default Value Expressions?

Thanks

24 Comments
ChristyFung

I hope this feature would be added to field maps, allowing us to manually edit the calculated values are essential since sometimes the values are not correct,

JohnFannon

A calculated default value that remains editable (if the field is editable) is absolutely a requirement. The field calculations are generally there to speed up and simplify data collection, but should not prevent the user overriding them if required.

JustinReynolds

This has been implemented in AGO and AGE @ 11.1.

LanceKirby2

@JustinReynolds Could you specify what feature has been implemented in AGE 11.1? Is it just the toggle switch logic you showed in your gif along with edits to the source JSON? Or is there an actual feature to allow for users to overwrite calculated values that I am missing? 

JustinReynolds

@LanceKirby2 

The ability to natively author editable expressions and Form Calculations in Field Maps Designer are what I am referring to. In my previous post with the GIF, I was implementing this without native support. 

You no longer need to make edits to the JSON directly in order to deploy the editable expressions. Editable Expressions are the piece you need in order to allow users to edit (overwrite) calculated values.  There isn't a specific feature that will "allow users to overwrite". You will need to setup the logic using Arcade to make it work, but now you have the tools that you need to make it work without having to deal with AGO Assistant.

I just so happened to tie that previous example to a switch, but you don't need the switch to make it work.  In other cases I simply calculate the field if it is null | Empty... otherwise if it is already calculated, then the user can edit it.  This is the idea around calculated default values... on INSERT the field is null, so it get calculated... but after it is calculated the user can edit the field.  This is possible because of the editableExpression.

Hope that helps.

lah
by

@JustinReynolds I am also not getting this ability in AGE 11.1. Are you working with hosted feature layers?

MarkEastwood

@JustinReynolds 

"I just so happened to tie that previous example to a switch, but you don't need the switch to make it work.  In other cases I simply calculate the field if it is null | Empty... otherwise if it is already calculated, then the user can edit it.  This is the idea around calculated default values... on INSERT the field is null, so it get calculated... but after it is calculated the user can edit the field.  This is possible because of the editableExpression."

 

This is exactly how I would like some of my editable fields to be configured but I don't seem to be allowed to have a calculated expression while also being allowed to edit the field. Could you provide some screenshots of your form configuration? 

JustinReynolds

@MarkEastwood Well, ESRI seems bent on making me out a liar.  As I went to create an example for you on this something as clearly changed recently; probably with the June release as Forms that were working as expected no longer do. The field calculates (in some cases) and the user can change the value, but if they null the field again it no longer re-calculates.

If I had to guess it has something to do with them deprecated "editable" and replacing it with "editableExpression" or the execution logic.  ESRI reads your Form and builds an execution map or tree of sorts so that the Form execution is as efficient as possible.

I works great if my editable logic is based on a different field (e.g. using a switch to toggle editability), but is unstable or flawed if the editable expression is based on itself (e.g. checking for null on itself).

Here is how it worked a month or so ago.

The overall setup... Shown using AGO.

The overall setupThe overall setup


The editableExpression

JustinReynolds_1-1690928202754.png

JustinReynolds_2-1690928604846.png

The form calculation

JustinReynolds_3-1690928673685.png

JustinReynolds_4-1690928694326.png

 

MarkEastwood

Thanks @JustinReynolds, I really appreciate the time you spend answering these questions.

Very frustrated with ESRI's recent development, nothing ever seems to work as it is advertised. 

Gavin_Leavitt

@JustinReynolds @MarkEastwood In iOS FM, using the AGO Forms builder, I have a field that calculates to a default value, can be overwritten directly if needed, and re-calculates to default value with editability if nulled by the user.

This is on a date field named "Date1", the field is set to required in the form and I am not using a separate field to determine editability. 

Editability Expression:

 

 

 

!IsEmpty($feature["Date1"])

 

 

 
 
Calculated Expression:
 
 

 

 

var current = Now()
var exist = $feature.Date1
if (!IsEmpty(exist)){
  return exist
}
return current
 

 

 

We don't use AGE so I don't know if the most recent updates that enabled this are available on there yet. I also noticed that nothing happens on the current version of FM on Android, no calculations occur but the fields are editable.