Calculating and Pulling Data Into Forms

Sometimes when you're editing a form, you want certain fields to calculate rather than be entered by the user. Sometimes this might be a matter of calculating a total, for example - other times it may involve pulling in fields from a form you're linking to, to show them to the user.

 We'll show you how to do both of these.

Let's say you have two fields, one called Price and another called Quantity. You want a third field, Total, to be the sum of Price and Quantity. How do you do this?

In the workflow editor, when adding fields, there is an option called "Initialize". Set that to Calculation, and then in the Default Value field put something like this:

#input/Quantity * #input/Price

 ...this sets that field to be *calculated* according to the formula. The formula itself should be self-explanatory, but for more information read through our introduction to DbfScript.

 When you republish, you'll notice that the field is now grayed out and can't be edited - that's because the value is calculated rather than edited. When you change the Quantity or Price, you'll notice that the calculated field updates automatically with the sum of the two.

 So this is one way to create a calculation field. You can also use it with dropdown link fields, like for example pulling in information from a Customer field.

 Let's say you had a Customers tab. Then you had a field called Customer in your form that linked to that. A link field will just show the title of the customer - say the customer name, however you may want to see other details about the customer. So you can then have a calculated field in your form that pulled in some other information from the Customer tab into your form. For example,

#input/Customer/Address

 This formula will pull the Address value of the selected Customer into your form. Just set that formula on a new field, set to Initialize=Calculated, and after you publish whenever you select a customer it'll automatically update the Address field with the customer's address.


Next Topic:
v4.2.0.956 (beta)
Up Since 2/29/2024 12:02:23 AM