People Goal 5 - Part 3: Trigger your sort script

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

 


Now that you’ve written a script to sort your Main List records, let’s make the script run automatically whenever the user views the layout, ensuring that the Last Initial subsummary part is displayed consistently. This automation is accomplished by using a script trigger.

 

Script triggers cause scripts to execute when certain events take place, such as when a layout loads, a window opens, or when a field value is changed via the interface. FileMaker Pro provides many different script trigger options to choose among. They are associated with the following events:

 

  • Files or windows being opened or closed

  • Various actions being performed on a layout such as loading the layout or entering Browse mode

  • Various actions being performed on layout objects such as fields or buttons

  • A given interval of time passing

 

 

It’s beyond the scope of this training to cover script triggers comprehensively. For more detailed information see this help page.

 

In this case, you’ll use the OnLayoutEnter trigger, which causes a script to run when you change from one layout to another. Note that deciding what trigger to use takes thoughtful evaluation — click here if you’d like to know why we chose this one.



Goal:


Associate a script trigger with the Main List layout that causes the "Sort Contacts" script to run whenever the user switches to this layout or enters Browse mode.



Steps:


Set up the script triggers

 

  1. Make sure you are viewing your Main List layout in Layout mode.

  2. Choose the Layouts menu > Layout Setup…

    A Layout Setup dialog window appears.

  3. Switch to the Script Triggers tab.

  4. Select the OnLayoutEnter option from the Event list.

    A Specify Script dialog window appears.

  5. Select your new sort script.

    In the example solution, the script is “Sort Contacts”.

  6. Select only the Browse and Preview checkboxes for the Enable In option.

    The script will only be triggered for those modes that you select. Since sorting is not relevant for Find mode, it’s best not to select it. You get a small performance improvement by not calling the script unnecessarily.
    pasted-image-8.png

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

  8. Click the OK button to dismiss the Layout Setup dialog window.

 

 

Test the script trigger

  1. Choose the Records menu > Unsort

    The records are returned to their original unsorted state and the subsummary part disappears. If this menu command is grayed out, the records are already in this state.

  2. Switch to your Main Detail layout.

  3. Switch back to your Main List layout.

    When you enter the Main List layout, your script trigger causes your sort script to run, sorting the found set and causing the Last Initial subsummary part to be displayed.



 

      

      

Attachments

    Outcomes