Performing calculations in repeating tables

Calculations in repeating tables might not work on your mobile device they way they work in InfoPath. As a rule of thumb, remember that setting field values with rules tends to be more robust than with default values, and everything is more robust outside repeating controls. This article explains two pitfalls in form design and how to avoid them. 

Pitfall #1: Screen Refresh

In InfoPath the PC screen is usually very snappy about showing instantly the updated value of a calculated field when another field value changes. Mobile devices are less reliable about showing updated values in Formotus forms. Sometimes the calculation has been made but the textbox will not show the new value until something triggers it to refresh.This is particularly prone to happen when the changed values are inside a repeating table and the calculation needs to be displayed  outside that table.

Best Practice:  Use rules on a button rather than default values on textboxes to extract calculations from a repeating table. In the screenshot below, the Line Total value successfully calculates across using a default value formula, but the Subtotal and Total values below might have problems. Therefore we used a Calculate button with rules to set the values of those fields, and performance is much more robust. Note: As a safeguard you can add a calculate rule to your submit button as well to make sure the action is not omitted.

infopath-repeating-table-calculations.png

Download this InfoPath form to see how it works

A variation on this best practice is to move highly complex business logic outside the repeating control, then copy it back in with a rule. For example, if you have a dropdown list populated by a complex formula that queries a data source, it might need to reside outside the repeating table. Then inside the table you can put a button that copies the resulting value into a text box.

Pitfall #2: Data Structure

InfoPath is very forgiving of where in the data tree the calculated value field resides, but Formotus has stricter requirements. Notice in the screenshot above that the Subtotal field is a sibling of the MyTable repeating group (both under TableGroup). This is very important, because if it were instead located in the position of the WrongPlace field, that could cause problems on the mobile device.

Best Practice: Make sure any field that extracts a calculation from a repeating table resides as a sibling under the same parent group as the repeating table.

Have more questions? Submit a request

0 Comments

Article is closed for comments.