Creating Custom Action Scripts

Description

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:

  1. Select the "Customers" table on the Tables/Sets tab in the Control Panel.

  2. Right-click the "Customers" table and select Open Default Form.

  3. Click the Design button to switch to Design Mode. Your screen should look like this:

    images/Custom_Action_Script_1.gif
  4. 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.

  5. Enter "Save Record" as the button label.

  6. Make sure the check box and radio buttons are set as shown above:

  7. Click Next >. The embedded Action Script Editor appears. Picture

    images/Embedded_Action_Script_Editor.gif
  8. Click the Add New Action button.

  9. 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.

    images/Custom_Action_Script_5.gif
  10. Click Finish to complete the Action. The embedded Action Script Editor looks like this:

    images/Custom_Action_Script_6.gif
  11. Click Add New Action button again.

  12. Select the "Records" category, and the "Enter New Record" Action. Click OK. The Genie appears.

  13. 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:

    images/Custom_Action_Script_8.gif
  14. To set the default value in the country field, click Add New Action.

  15. 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.

  16. 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:

    images/Custom_Action_Script_10.gif
  17. 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.
    images/Custom_Action_Script_11.gif
  18. Enter "United States" at the Value prompt and click Finish to complete the Action. The embedded Action Script Editor now looks like this: Picture

    images/Custom_Action_Script_12.gif
  19. Now create the final action which will give focus to the firstname field. Click Add New Action.

  20. Select the "Object Properties (Set and Get)" category, select the "Activate an Object" Action, and click OK.

  21. 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.

  22. Select the Firstname object and click OK. Your screen should now look like this:

    images/Custom_Action_Script_15.gif
  23. Click Finish. The embedded action script now has four actions:

    images/Custom_Action_Script_16.gif
  24. Click the Save button to save the form. Give the form any name you want.

  25. Click the Form View button to run the form.

  26. 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.

    images/Custom_Action_Script_17.gif

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.