Scripting Fundamentals

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 JavaScript: You use JavaScript to write custom scripts that add functionality to your forms like you use JavaScript to add custom functionality to a web page. Designer also includes another language, FormCalc, which is covered later in this section.
  • 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.
  • Range of scripts: Because JavaScript is a rich, object-oriented scripting language; you can write an incredible range of scripts, from very basic one-line scripts to complex and detailed, object-oriented scripts that can span hundreds and even thousands of lines.

If you’re familiar with JavaScript, you’ll find the scripting concepts in Designer to be very familiar. However, since Designer uses the XFA object model, it is not exactly the same as writing JavaScript for web pages.

Scripting in AEM Forms Designer

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.

AEM Forms Designer Scripting Fundamentals

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.

Subscribe Today!

Are you getting the most out of your Adobe AEM Forms software?

You can today by accessing the remainder of this course, as well as 33 other AEM Forms courses with your SmartDoc Subscription.

  • Access the world’s premier AEM Forms training any time, any place, anywhere
  • Join our weekly instructor-led training sessions
  • Master Adobe AEM Forms for as little as $179./month

Find what you've been searching for with your SmartDoc Subscription.