Select to view content in your preferred language

Only calculate fields once

701
2
Jump to solution
06-26-2023 12:13 PM
KPyne
by
Regular Contributor

Hello everyone,

I have a rather large form broken into groups of questions. Pieces of the form are filled out over time and as sections are completed they are "closed" for editing. Most of them calculate in the background (hidden).  

My issue is that by the time users get to the end of the form, there are many calculations triggering each time any field is edited, even fields that only need to populate once such as an ID or a creation date field.

I have each calculation fields checking for pre-existing values that way its not performing the more extensive portions of arcade. EX:

 

if (!isEmpty($feature.RecordID)) {return $feature.RecordID}

else {return *script for generating ID*}

 

I know calculations need to repeatedly search for edits and change dynamically, but is there a more efficient way to skip calculating once initially populated?

 

1 Solution

Accepted Solutions
SarahSaint-Ruth
Esri Contributor

The script you mention is the recommended best practice for retaining values during an edit operation. Its pretty efficient because its checking the condition and not running through the calculate again.

Slightly different to the use case you mention above, however we often find folks are affected by both your scenario, and the scenario that you want to maintain values between editing operations i.e. only run on inserting a feature, don't run on an update of an existing feature. In this case you can use:

$editcontext.editType=="X"

X being either INSERT, UPDATE or DELETE (delete isn't really relevant to the calculate profile in Field Maps as calculations will not run on a delete operation). You can then say something like: 

if ($editcontext.editType=="INSERT"({
var userInfo = GetUser($layer,'');
return (userInfo["fullname"]);
else {
return $originalFeature.collector_name;
}

 

View solution in original post

0 Kudos
2 Replies
SarahSaint-Ruth
Esri Contributor

The script you mention is the recommended best practice for retaining values during an edit operation. Its pretty efficient because its checking the condition and not running through the calculate again.

Slightly different to the use case you mention above, however we often find folks are affected by both your scenario, and the scenario that you want to maintain values between editing operations i.e. only run on inserting a feature, don't run on an update of an existing feature. In this case you can use:

$editcontext.editType=="X"

X being either INSERT, UPDATE or DELETE (delete isn't really relevant to the calculate profile in Field Maps as calculations will not run on a delete operation). You can then say something like: 

if ($editcontext.editType=="INSERT"({
var userInfo = GetUser($layer,'');
return (userInfo["fullname"]);
else {
return $originalFeature.collector_name;
}

 

0 Kudos
KPyne
by
Regular Contributor

Good to know I was on the right path. The editType check sounds very useful as well!

Thank you!

0 Kudos