People Goal 5 - Part 4: Import a script from Landscaping

Document created by Kedar on Feb 4, 2015Last modified by communitymanager on May 12, 2015
Version 22Show Document
  • View in full screen mode

 


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.



Goal:

 

Import a script that helps to add a new portal row and modify it to work in your solution.

 

 

Steps:


Import the script

 

  1. Choose the Scripts menu > Script Workspace…  ⇧⌘S or Ctrl S

    A
    Script Workspace… window appears.

  2. Choose the Scripts menu > Import… 


    An Open File dialog window appears.

  3. Browse to your Landscaping file and select it.


    An Import Scripts dialog window appears, showing the scripts in your Landscaping file.

  4. Select the checkbox next to the “Create New Work Order” script.
    import script from landscaping.png

  5. 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.
    import summary.png


  6. 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.

  7. 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.
    imported script with errors.png
  8. 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

 

  1. 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.

  2. Select your secondary table occurrence.

    In the example file, this is “Activities”.


  3. Select one of the fields from your secondary table that appears in your portal.

    In the example, this is “Activities::Type”.


  4. 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:

  5. 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:

    imported script progress.png


    Finally, let’s address the third error:

  6. 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:

    imported script finished.png

    The script is finished, so you can close the edit window and save your changes.

  7. 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?”

  8. Click the Save button.

    The dialog box disappears and the script disappears from the center pane.

 

 


Add a button

 

  1. Make sure you are viewing the Main Detail layout in Layout mode.

  2. Select the Button tool in the status toolbar.

  3. Drag a rectangle to create a new button just above the right-hand side of the portal.


    portal button.png



    A Button Setup dialog window appears.

  4. Choose the fifth option from the first row, to indicate that an icon will appear to the left of the button label.

  5. In the empty box, enter the following label: [Secondary Tablename]


    The example solution uses “Activity”.
    button label activity.png

  6. Select the first + icon from the icon grid.
    button plus icon.png
  7. Use the slider to change the icon size to 12 pt.
    button icon slider 12pt.png


  8. Change the Action to "Perform Script".
    button action perform script.png

    

A Specify Script dialog window appears.

 

  1. Select your new “Add portal row” script.

  2. Click the OK button to dismiss the Specify Script dialog window.


Test the button

 

  1. Switch to Browse mode.

  2. 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.


      

      

Attachments

    Outcomes