Scripting gives you full control over your form’s functionality at runtime. Through scripting, you have the power to manipulate your form’s interactive controls to provide your users with a richer and more intuitive experience. Designer scripting is similar to HTML scripting in the following ways.
- Use of an object model: Like web programming, Designer has an object model that you can use for your scripting. You can call methods and properties of the object model to provide rich functionality to your forms.
In many cases, scripting improves the functionality and usability of your forms. A number of useful scripts are included in the Purchase Order form in your Student Files. One of these handy scripts is found in the Add Item button’s click event. This script creates a new line item in the purchase order each time the button is clicked.
Another practical script is found in the Grand Total text field (numGrandTotal). This script automatically calculates the grand total for the purchase order every time a financial event on the purchase order occurs. When a new item is entered or when a new tax is applied, the grand total is recalculated automatically. This is a useful script for form fillers because they can see how all their changes and additions to the Purchase Order affect the bottom line. Unlike the previous script, which ran on the click event, this script runs on the calculate event of the numeric field.
Although scripting is not a requirement in Designer forms, a small investment in scripting will yield the following benefits to you and your form filler.
- Automatic calculations at runtime: As described in the Purchase Order example, the addition of automatic calculations will make your forms much more useful to your form fillers.
- Ability to control the appearance of form objects at runtime: In the previous section, you set the visual properties of your form objects at design time. With scripting, you can make changes to the visual properties of your form at runtime to provide assistance to your form fillers. For instance, before your user submits a form, you can use a validation script to make sure that all the required fields have been filled in with data. If there are required fields without data, you can call a script to highlight them in yellow. This way, the form filler’s attention will be drawn visually to the required task.
- Enforcement of business rules: You can use form scripting to enforce the business rules of your company or industry. For instance, the Purchase Order example could have a script that takes an action whenever the grand total goes above a certain threshold. You could create a script that limits users from going above a certain amount, or you could allow them to go above the amount and automatically route the purchase order for a senior manager’s approval.
- Data validation and formatting: In addition to using patterns and properties to enforce data validation, you can use custom scripting. This approach is valuable because you’ll be able to correct many data-entry mistakes before they get to your back-end system.