In the Learn phase, you created a script that helped to automate the process of adding new records to a portal. Let’s import that script from your Landscaping solution to use here as well. If you don’t have your Landscaping file any more, that's not a problem: download the example files from the Learn phase and look for our finished version of the file.
Importing scripts and adapting them to your needs can save you a lot of time. We recommend that you try importing scripts from the Starter Solutions as a way of learning new scripting approaches.
NOTE: While FileMaker Pro can import scripts from other files, FileMaker Pro Advanced also allows you to copy scripts and groups of script steps from one script to another, making it easy to reuse parts of your scripts in other scripts or in different solutions.
When you’re done with this script, it should resemble “Add Portal Row” in the example solution.
Import a script that helps to add a new portal row and modify it to work in your solution.
Import the script
- Choose the Scripts menu > Script Workspace… ⇧⌘S or Ctrl S
A Script Workspace… window appears.
- Choose the Scripts menu > Import…
An Open File dialog window appears.
- Browse to your Landscaping file and select it.
An Import Scripts dialog window appears, showing the scripts in your Landscaping file.
- Select the checkbox next to the “Create New Work Order” script.
- Click the OK button.
An Import Summary dialog window appears. Don’t worry if it reports some errors — you'll fix them in a moment.
- Click the OK button.
You are returned to the Script Workspace. The imported script now appears in the list of scripts in the left pane.
- Click the name of the script.
The script opens in the center pane. It should look like the image below. Note the three places where a field name is missing.
- Double-click the name of the script (in the tab in the center pane) and change it from “Create New Work Order” to this: Add portal row
Fix the errors
- Click on first “Go To Field” step where it says "<Table Missing>".
A Specify Field dialog window appears. At the top there is a drop-down allowing you to choose a table occurrence.
- Select your secondary table occurrence.
In the example file, this is “Activities”.
- Select one of the fields from your secondary table that appears in your portal.
In the example, this is “Activities::Type”.
- Click the OK button.
The Specify Field dialog window disappears, and your script step displays the name of the field that you chose.
Now let’s address the second error. Consider whether you need to set the values of any fields in your secondary table. This is unlikely because when you set that table up, we encouraged you to use auto-enter options to take care of this.
Assuming you don’t need to set any fields:
- Delete (or modify) the Set Field script step and the # comment line above it that says "This populates the Date field in the new related record".
This is easy — just select the two script steps and press the delete key.
At this point, the script should look something like this:
Finally, let’s address the third error:
- Repeat steps 9 to 12 for the final Go to Field step, also modifying the comment above it as appropriate.
The finished script should look like this:
The script is finished, so you can close the edit window and save your changes.
- Close the script by clicking the X that appears when you hover over the tab in the center pane.
A dialog box appears, asking “Save changes to “New Script” first?”
- Click the Save button.
The dialog box disappears and the script disappears from the center pane.
Add a button
- Make sure you are viewing the Main Detail layout in Layout mode.
- Select the Button tool in the status toolbar.
- Drag a rectangle to create a new button just above the right-hand side of the portal.
A Button Setup dialog window appears.
- Choose the fifth option from the first row, to indicate that an icon will appear to the left of the button label.
- In the empty box, enter the following label: [Secondary Tablename]
The example solution uses “Activity”.
- Select the first + icon from the icon grid.
- Use the slider to change the icon size to 12 pt.
- Change the Action to "Perform Script".
A Specify Script dialog window appears.
- Select your new “Add portal row” script.
- Click the OK button to dismiss the Specify Script dialog window.
Test the button
- Switch to Browse mode.
- Click the button.
Are you taken to the last row in the portal in order to create a new row?
If so, you have successfully imported your first script, adapting it to your new solution! It can save you a great deal of time to work with scripts in this way.