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.
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).
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.
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).
13 .In the Files section of the step list on the left, double-click Perform Script (Figure 7.56).
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).
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.
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).
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).
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.
When 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.
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.
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).
4 .In the Specify Calculation dialog box, choose Get functions from the View drop-down list (Figure 7.64).
5 .
Scroll down to Get(ScriptParameter) and double-click it (Figure 7.65). Click OK three times to finish.
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.