Creating a Script to Print a Report for a Selected Record
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.
Click the New button on the Code tab of the Control Panel and create a new script using Action Scripting.
Click the Add New Action button.
Select the "Reports" category and the "Preview a Layout" Action.
- All the different report types (reports, labels, letter, etc.) are collectively referred to as "Layouts."
The Preview a Layout Genie appears.
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.
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.
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.
Click the green '+' button to add the first condition to the filter. The Add Condition dialog box appears.
To search in the Lastname field, select "Lastname".
As soon as you click on a field, the Operator column is enabled.
Select the "is equal to" operator.
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.
Click the Customize Parameter button.
The Define Parameter dialog box appears. Picture
To present the user with a list of last names, change the Style of the parameter. Select "Record List-List Box".
Click the Define Record List button to display the Define Record List dialog.
Select "customers" for the Table name.
Select "Lastname" for the Field name.
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.
Click OK to close the dialog box and then click OK twice to return to the Script Genie screen.
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.
Click Next > and Finish to complete the Action.
The Code Editor should now look like this:
Click the Save button.
Enter "PrintMailLabel_forLastnm" as the script name. (Alpha Anywhere limits script names to 24 characters.)
Now test the script. Click the Run button on the toolbar.
Alpha Anywhere prompts for the customer's last name. Select "Barber" and click OK.
Alpha Anywhere displays the mailing label for "Tom Barber." Picture
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.