Can I force a calculation when updating a feature in a child from?

1206
9
Jump to solution
11-07-2019 06:05 AM
BenjaminSperry1
Occasional Contributor

I have a feature service with a parent table and several related child tables.

Each child table supports a part of a weeks long workflow and has its own form that references the feature service. Responses entered in the child tables update fields in the related parent. I want this to happen in the background, however I can't seem to modify parent fields without manually refreshing the calculation.

If a create a new record with this form the calculations are automatic, but updating the parent requires clicking on this button.

For example:

Here is a simple form with a repeat:

typename
geoPointlocation_pointThe point location
dateTimeevent_dateThe date the point was collected
begin repeatchildThe child table
integerentrySome data entry that triggers a change to the parent
end repeat
textevent_closedThe event was closed

The first two are collected in the initial collection form:

typename
geoPointlocation_point
dateTimeevent_date
hiddenevent_closed

The repeat and the "event closed" are collected in a child form:

typename
geoPointlocation_pointRead only (used for reference)
dateTimeevent_dateRead only
begin repeatchildThe child table
integerentrySome data entry
end repeat
calculateevent_closedif(sum(${entry})>1,"yes","no")

In the child form "event_closed" is invisible because it is set to a calculation. It should populate the parent field with either "yes" or "no" depending on the data collected, but it is not working that way.

When I expose the field in the form by changing from "calculate" to text I see the refresh button

which I have to manually press for the calculation to take place.

Is there any way to force this calculation so it doesn't require user input?

Survey123 - 3.6.153 (android and PC)

Survey123 Connect - 3.6.137

ArcGIS Enterprise 10.7.1

1 Solution

Accepted Solutions
AnaDeniston
New Contributor II

I had the same issue. 

The calculationMode parameter entered in the bind::esri:parameters column controls when calculations in questions are calculated, for example, calculationMode=manual. There are three supported values:

  • auto—Calculate when the question is empty or has not been previously modified by the user. If no value is provided, this is the default calculation behavior.
  • manual—The question will only calculate when clicking the Calculate button next to the question.
  • always—Calculate when any value referenced in the calculation expression changes. This includes dynamically changing functions, such as now().


This link explains how to calculate it:

Pre populate answers

 

View solution in original post

0 Kudos
9 Replies
JamesTedrick
Esri Esteemed Contributor

Hi Benjamin,

Calculations are done automatically.  It may be helpful if you could share the XLSX file so that we could see in more detail what is occurring.  That being said, once the value of a question differs from the calculation, re-engaging the calculation requires pressing the recall button.  This also occurs when loading a form from the drafts or Inbox; if a value is null, for example, it will stop updating based on the calculation.

0 Kudos
BenjaminSperry1
Occasional Contributor

Hi James,

Is there a way to recalculate an entire form?

Like you mention above because I use the inbox to open many of the forms (editing existing records rather than creating new ones) I have to press the re-calculate button for each field. I have six or so fields that have to be recalculated each time; it would be useful to be able to recalculate the whole form at once instead of having to recalculate each field individually.

Some context to what I am trying to do:

A technician collects a sample from the field and creates a record using Collector. Later the sample is examined in the lab and a lab technician fills in the rest of the information for that record. Many of the fields are calculated based on what the lab technician enters. Ideally these would calculate automatically even thought they are technically already "NULL" .

Thanks

0 Kudos
BenjaminSperry1
Occasional Contributor

Hi,

I found a work around to recalculate the whole form.

When you have conditions set in the "Relevant" column it resets the value and automatically runs the calculations on a field when the condition is met.

Notes:

1. This method should be used with caution because if the field does not meet the condition than any value that was already populated will be deleted and the value will be reset to null.

2. This doesn't work if the condition is immediately satisfied, e.g. if you set the condition to a static field. So I have a single question that I select "Yes" on and it updates the whole form.

If anyone find a better way I am happy to hear it.

0 Kudos
DougBrowning
MVP Notable Contributor

I had some luck giving it a dummy if statement like if(somefield, calc, samecalc).  You could maybe tie this to a time as well. Maybe if(starttime != now(),calc, calc) where start time is a build in field.  Then basically you know they opened it again.  today() may be better otherwise this may fire it a lot.  Either way I worry a little if you are having too many fields recalc all the time it could slow the form.

Other way i use a lot is Arcade so it is always dynamic.  If someone edits the data in a web map then 123 calc does not fire so this is safer for me.  Depends on your workflow.

Yet another option is attribute rules that recalc the parent when the data is changed.  I think you need a non hosted feature service for this to work however.

Not sure but it is an idea.

0 Kudos
BenjaminSperry1
Occasional Contributor

Thank you Doug,

No luck with the if statement, I think it has to do with there being an existing value (even if it is null). I am very open to other workflows to solve the problem. It is a hosted feature service in AGOL so I don't believe that you can set attribute rules -- but I will look into that.

How do you use Arcade? So far all I have read is that you can use it in popups and symbology but not to commit calculations; is there a way to use Arcade to automate the calculations? Manually doing field calculations would have limited utility for my workflow.

Thanks

DerrickWestoby
Occasional Contributor III

Hey Benjamin, I'm not sure if you saw this month's blog/release notes, but the "recalculate" URL parameter was added. 

https://community.esri.com/t5/arcgis-survey123-blog/whats-new-in-arcgis-survey123-september-2021/ba-...

  • A new URL parameter lets you force the recalculation of a question when the form is opened in edit mode in the Survey123 web app.

 

0 Kudos
TristanGingras-Hill
New Contributor II

Hi Benjamin, 

I'm having a similar issue. Would you mind demonstrating where you implemented the relevant comment to force the calculation? 

Thank you

TristanGingras-Hill
New Contributor II

There is now a way to do this by using an indexed-repeat outside the initial repeat referencing the previous repeat. 

See xls file. 

0 Kudos
AnaDeniston
New Contributor II

I had the same issue. 

The calculationMode parameter entered in the bind::esri:parameters column controls when calculations in questions are calculated, for example, calculationMode=manual. There are three supported values:

  • auto—Calculate when the question is empty or has not been previously modified by the user. If no value is provided, this is the default calculation behavior.
  • manual—The question will only calculate when clicking the Calculate button next to the question.
  • always—Calculate when any value referenced in the calculation expression changes. This includes dynamically changing functions, such as now().


This link explains how to calculate it:

Pre populate answers

 

0 Kudos