3 Replies Latest reply on Nov 21, 2013 12:29 PM by philmodjunk

    How to replicate function used by the "Projects" database



      How to replicate function used by the "Projects" database


      Hi all, I am new to FMP but need some help to duplicate functionality that is used in the example “Projects” DB provided by the FMP software by default.

      In the “Projects” example DB, they have a projects layout to capture info on the project that is stored in the projects table, then there is  a button that takes you to the “tasks” layout where you enter tasks associated with that project. Once you enter the tasks, those are stored in a separate table but are now associated to the project you came from so that you can see the list of tasks in the projects. Any new project would have its own list of tasks. This is the functionality I need to replicate. I have a table of customer info, but have a separate table for other info and need to link these like this. I can see that a small script is used for the button, but I am not sure how to replicate this.

      This seems like pretty basic process and once I have seen it done I am sure I can apply as needed to my project im working on. Can anyone tell me what this functionality is call so I can search for it or link a video or article I can read to learn how to do this?

      Thanks for all your help. 

        • 1. Re: NoFields

               The first step is to link the tables in a relationship in Manage | Database | Relationships.

               In the starter solution, you have:



               If you use Manage | Database | Fields to find and open field options for Tasks::PROJECT ID MATCH FIELD, you'll find that it has this auto-enter calculation:


               That will enter the value of this global variable each time a new tasks record is created.

               What your "short script" does is set this variable to the value of Projects::PROJECT ID MATCH FIELD from the current record on your Projects layout.

               This is not the only way to create and link child records to a parent record. Often, a portal to the child table (tasks) is used for that purpose. If "allow creation of records via this relationship" is enabled for Tasks in this relationship, you can create new records in a Portal to Tasks on a Projects layout by entering data into the bottom blank "add row" that this options puts in the portal. This does method does not require scripting nor does it require the auto-enter calculation. Many of the starter solutions use both methods with a portal on the desktop layouts and the script/global variable method used on the iPhone layouts.

          • 2. Re: NoFields


                 Just curious if you have a link to a walk through or tutorial of the first method you discussed. I am familiar with the second and have done that but I need to do the first for a cleaner interface. 



            • 3. Re: NoFields

                   Nearly all the details are in my last post, but here they are arranged in stepwise fashion.

                   Open Manage | Database | Fields

                   Double click your child table's match field such as PROJECT ID MATCH FIELD in Tasks to open Field Options.

                   On the auto-enter tab, select the calculation option and enter the name of a global variable such as $$CURRENT_PROJECT_ID. Before you click OK to close the Specify Calculation dialog box, copy the name of this variable to the clip board.

                   Now click OK to leave Manage | Database and go to your Parent layout (Projects).

                   Enter layout mode and select Layout Setup from the Layout's menu.

                   Click the Script Triggers Tab

                   Select the OnRecordLoad Trigger

                   In the Specify Script Dialog, click the button with the + to create a new script.

                   Enter this script:

                   Set Variable [$$CURRENT_PROJECT_ID ; value: Projects::PROJECT ID MATCH FIELD ]

                   Paste the variable name from the clipboard as a way to make sure that you don't accidentally use a different variable name.

                   Click OK until all Dialog boxes are closed and enter browse mode.

                   Note the value in Projects::PROJECT ID MATCH FIELD

                   Go to the layout for Tasks and create a new record and note that the same value appears in Tasks::PROJECT ID MATCH FIELD

                   The key limitation to watch out for is that this requires that you always go to the child table layout (tasks) form the Parent table layout (Projects) in order to make sure that the correct value is loaded into the global variable. If a user opens the data base and goes directly to Tasks and creates a new record, the new record will have an empty match field as the global variable was never set to a value first.