In "Combining Sub-Scripts" we ran scripts from inside a master script. However, all of the sub-scripts we used were in the same file as the master script. Scripting also allows you to run scripts in other files. Doing so allows you to access data from a second file while working in the first database.In this example, we create a master script that brings us to the Customer layout in the Customer file (where customer data is kept) from the Project file (where sales data is maintained). You might use this script to get contact information from a new customer's invoice in the sales file and import it to your customer database.
To run a script in another file
1 .Go to the file that will be called by the external script. In our example, we use the Customer database.2 .Choose Scripts > ScriptMaker (Control+Shift+S/Command+Shift+S).3 .When the Define Scripts dialog box appears, click New.4 .When the Edit Script dialog box appears, type a name for the script (Figure 7.53).
Figure 7.53. Use a script name that describes what the script will do.
5 .In the step list on the left, double-click Go to Layout in the Navigation section to add it to the script-assembly list.6 .In the Script Step Options section, choose your report layout from the Specify drop-down menu (Figure 7.54). In this example, we choose Customer Entry. Click OK twice to finish.
Figure 7.54. Select a layout whose fields contain data you need in the external file.
When this script runs, it will switch to the Customer Entry layout in the Customer file.7 .Open the file in which you will create the script that calls the external script. In our example, we use ProjectVIP.8 .Choose Scripts > ScriptMaker (Control+Shift+S/Command+Shift+S).9 .When the Define Scripts dialog box appears, click New.10 .When the Edit Script dialog box appears, type the script name.11 .In the Files section of the step list on the left, double-click Open File.12 .In the Script Step Options section, select the Customer file from the Specify drop-down list (Figure 7.55).
Figure 7.55. Specify the file you want to open in the Script Step Options.
13 .In the Files section of the step list on the left, double-click Perform Script (Figure 7.56).
Figure 7.56. Use Perform Script to call an external script.
14 .In the Script Step Options section, click Specify.15 .When the "Specify Script" Options dialog box appears, select the Customer database from the drop-down menu (Figure 7.57).
Figure 7.57. Choose the database that contains the external script you want to run.
The list of scripts will change to those in the Customer database.16 .Choose the script that you want to run from the scrolling list (Figure 7.58). Click OK.
Figure 7.58. The "Specify Script" Options dialog box lists all of the scripts in the external file.
The Perform Script step in the script-assembly list will change to tell you which script will be run, and in which file it will run (Figure 7.59).
Figure 7.59. Both the name of the external file and the name of the script are listed in the Perform Script option brackets.
17 .In the step list on the left, double-click Select Window from the Windows section to add it to the script-assembly list (Figure 7.60).
Figure 7.60. The Select Window step brings the specified window to the front.
18 .In the Script Step Options, click Specify.19 .When the "Select Window" Options dialog box appears, click the Window Name radio button and type Customer (Figure 7.61). Click OK twice to finish. When this script is run, it opens the Customer layout in the Customer database, where you can edit or add data.
Figure 7.61. Type the name of the window you want to activate.
TipWhen the last command in a script performs another script, the script sequence will end when the second script finishes. As a result, you'll often end up in the layout and database where the external script ran, not in the original layout and database where you ran the master script. A common technique to return you to the other database is to use Go to Layout [original layout] as the last step in a script (Figure 7.62). This technique will work even if the sub-script was in another file.
Figure 7.62. Adding the Go to Layout step to the end of a script returns you to the database and layout from which you ran the script.
There may be times when you will want to run a script in another file and pass along some piece of information for the external script. For example, you can make the external script we created earlier go to a particular layout in the other file by passing the name of the layout with the script.
To specify parameters for external scripts
1 .In the file that contains the external script (in our case, the Customer file), Choose Scripts > ScriptMaker (Control+Shift+S/Command+Shift+S).2 .When the Define Scripts dialog box appears, double-click the Go to Customer Layout script to open the Edit Script dialog box.3 .Highlight the Go to Layout step in the script-assembly list. In the Specify drop-down list in Script Step Options, choose Layout Name by calculation (Figure 7.63).
Figure 7.63. Choose Specify: Layout Name by calculation to get the passed parameter from the calling script.
6 .In the file that will call the external script, choose Scripts > ScriptMaker (Control+Shift+S/Command+Shift+S).7 .When the Define Scripts dialog box appears, double-click the script that calls the external script (in our case, it's Go to Customer, created earlier in the section "To run a script in another file").8 .In the Edit Script dialog box, click the Perform Script step. In Script Step Options, click the Specify button.9 .When the "Specify Script" Options dialog box appears, type the desired layout name in the external file in the Optional script parameter box (Figure 7.66). Click OK three times to finish.
Figure 7.66. Data Entry will be sent to the external script as the parameter to choose the layout.