Keep the following guidelines in mind when adding scripts to your application.
Use procedures to perform process-intensive tasks. Doing so allows these tasks to be easily sent to a process server for remote processing. Refer to Background and remote processing for more information.
If your application contains code to validate data such as account numbers or customer IDs, move this code to form-level procedures or form-level functions. Don’t put validation code in field scripts. By placing the validation code in a form-level procedure or function, you make it available to other parts of the application that may need to perform the same validation.
To reduce code maintenance, avoid accessing data on other forms directly. For example, don’t explicitly refer to a window field on another form. Instead, create functions on that form to set and get the values of the field. Then you can make changes to the field without breaking code in other portions of your application.
Consolidate common operations like saving and deleting records into form-level procedures. Often, these operations are performed in several locations in the form. By consolidating these operations, you reduce code duplication and maintenance.