Creating Custom Action Scripts
While the Pre-Defined buttons are useful, they will not satisfy all your customization needs. You will need more elaborate, multi-step scripts that are executed when a user clicks a button on a form. This example creates a button that saves the current record, puts the form into Enter mode for entering a new record, sets the Bill_Country field default value to "United States," and then gives focus to the Firstname field, where the user can continue entering data for the new record.
To begin the lesson:
Select the "Customers" table on the Tables/Sets tab in the Control Panel.
Right-click the "Customers" table and select Open Default Form.
Click the Design button to switch to Design Mode. Your screen should look like this:
Select the Button Object tool on the Toolbox. While holding down the left mouse button, draw a button in the top right corner of the form. When you release the mouse button, the Define Button dialog box appears.
Enter "Save Record" as the button label.
Make sure the check box and radio buttons are set as shown above:
Click Next >. The embedded Action Script Editor appears. Picture
Click the Add New Action button.
Select the "Records" category, and the "Save Record" action and click OK. The Save Record Genie appears. To save the record in the current window, accept the default entries on this screen.
Click Finish to complete the Action. The embedded Action Script Editor looks like this:
Click Add New Action button again.
Select the "Records" category, and the "Enter New Record" Action. Click OK. The Genie appears.
The goal is to enter the new record in the current window, so do not make any changes to the defaults. Click Finish. The embedded Action Script Editor looks like this:
To set the default value in the country field, click Add New Action.
Select the "Fields" category, and the "Set Field Values" Action. Click OK to display the Set Field Values Genie. Leave the selection in the combo box as is.
Click button to select the field values you want to set. Although you can set the values of multiple fields in this action, you only want to select the value in a single field. Select Bill_country from the pop-up dialog box and click OK. Picture:
You can set the value of the Bill_country field to the following options. Your screen should look like this:
- a value that you specify now
- the value in a variable that was previously defined
- the result of some expression.
Enter "United States" at the Value prompt and click Finish to complete the Action. The embedded Action Script Editor now looks like this: Picture
Now create the final action which will give focus to the firstname field. Click Add New Action.
Select the "Object Properties (Set and Get)" category, select the "Activate an Object" Action, and click OK.
The Activate an Object Genie appears. To activate an object in the current form, leave the selection in the first combo box as is. Click on the Object Name list. This list shows all objects on the current form.
Select the Firstname object and click OK. Your screen should now look like this:
Click Finish. The embedded action script now has four actions:
Click the Save button to save the form. Give the form any name you want.
Click the Form View button to run the form.
Make some change to the record you're currently viewing and click the Save Record button. Note that Alpha Anywhere saves the current record, begins entering a new record, fills in "United States" and gives focus to the Firstname field.
In this lesson, you created a script for a button's OnPush event that included four different Actions. As mentioned earlier, there are other events besides a button's OnPush event. From here you can explore some of these other events and introduces you to the Pop-Up Action Script Editor.