Creating a Script to Print a Report for a Selected Record

Description

In this example, you will create a script that prints out a mailing label for a particular customer. The script will prompt the user for the customer's name. This script will be a Global Script. as you will recall, a Global Script appears in the Control Panel in the Code tab, and can be run by double-clicking the script name, or clicking the Run button.

  1. Click the New button on the Code tab of the Control Panel and create a new script using Action Scripting.

    images/Code_Editor_Blank_New_Action.gif
  2. Click the Add New Action button.

  3. Select the "Reports" category and the "Preview a Layout" Action.

  4. Click OK.

    • All the different report types (reports, labels, letter, etc.) are collectively referred to as "Layouts."
    • images/Action_Reports_Preview_a_Layout.gif
    • The Preview a Layout Genie appears.

      images/Print_1.gif
  5. To preview a Label, select "Label" the Layout Type list. A list of labels in the current Database appears. See Create a Label Layout for information about creating labels.

  6. Select "MailingLabels".

    images/Print_2.gif
  7. Click Next > to move to the next Genie page. Now you can select a filter to select which records should be printed. You want to be able to enter the name of the customer to print at run-time.

  8. Select "Prompt for Parameters at runtime". When you make this selection, note how an area under the list box becomes visible. You define the parameters in this area. Initially, the list is blank.

    images/Print_3.gif
  9. Click the green '+' button to add the first condition to the filter. The Add Condition dialog box appears.

    images/Print_4.gif
  10. To search in the Lastname field, select "Lastname".

  11. As soon as you click on a field, the Operator column is enabled.

  12. Select the "is equal to" operator.

  13. In the newly revealed Option column, select "Prompt at Runtime". You could stop here, and at runtime, Alpha Anywhere would display a prompt. However, if you customize the parameter, you can have Alpha Anywhere display a list of valid choices from which the user can select.

  14. Click the Customize Parameter button.

    • images/Print_5.gif
    • The Define Parameter dialog box appears. Picture

      images/Print_6.gif
  15. To present the user with a list of last names, change the Style of the parameter. Select "Record List-List Box".

    images/Print_7.gif
  16. Click the Define Record List button to display the Define Record List dialog.

  17. Select "customers" for the Table name.

  18. Select "Lastname" for the Field name.

  19. Click OK.

    images/Print_8.gif
  20. Click the Preview button to test the results. Alpha Anywhere shows a small dialog box showing how it will prompt the user for the lastname value.

    images/Preview_Button.gif
    images/Print_9.gif
  21. Click OK to close the dialog box and then click OK twice to return to the Script Genie screen.

    images/Print_10.gif
  22. The Genie now shows that the report filter contains one condition: "Lastname = a value that is prompted for at runtime". You could continue adding more conditions to the report filter, but for the purpose of this lesson, one condition is sufficient.

  23. Click Next > and Finish to complete the Action.

  24. The Code Editor should now look like this:

    images/Print_11.gif
  25. Click the Save button.

  26. Enter "PrintMailLabel_forLastnm" as the script name. (Alpha Anywhere limits script names to 24 characters.)

  27. Click OK.

    images/Print_12.gif
  28. Now test the script. Click the Run button on the toolbar.

  29. Alpha Anywhere prompts for the customer's last name. Select "Barber" and click OK.

    images/Print_13.gif
  30. Alpha Anywhere displays the mailing label for "Tom Barber." Picture

    images/Print_15.gif

Alpha Anywhere allows you to use special variables called "Ask" variables in filter expressions. Ask Variables provide an alternative to the above script as a method to prompt a user for input at runtime.