5 Replies Latest reply on Sep 14, 2010 5:56 AM by DanParadis

    Copying from a template to ...



      Copying from a template to ...


      Ok, let's see if I can explain this:

      I have two system tables:  Task_Template -->  Task_Template_Detail

      These tables may be copied to: Event --> Event_Tasks

      The attached script shows the respective Task_Template being found based on the type of Event.

      So far the script works great.  It finds the correct Task_Template and gets the Task_Template_Details records for that Event.

      Here's what I need to do:

      Check to see if there are already Event_Tasks records for the Task_Template

      if there are:

      Check with the user to see if we should delete the old and copy in the new (or overlay the old with the new).

      Forgetting all that for now:

      Once within the loop what is the best way to create the new Event_Tasks records based on the defaults from Task_Template_Detail records.  It seems if I create new rec's I lose the scope of the Task_Template_Detail records. 

      Can someone point me to an example on how something like this could be done?

      Once again: WOW... I programmed in other languages before (and as much as Filemaker makes other tasks simple) reading records is ridiculous!  Why can't it be simple to Read, Update, Create records without having to worry about losing the scope of the records you just read! 

      What am I missing?




        • 1. Re: Copying from a template to ...

          There's signficant info missing from your post. It's familiar to you because you built this system, but we can't see what you did from here just by looking at the script ;-)

          What layout is current when this script is performed?

          What relationships, if any exist between Events and Task Template?

          On a side note, I see two uses of Go To Related Record without any checking to see if there are any related records to go to. This can result in some pretty major problems when the script continues executing and is no longer even on the correct layout. A simple test Not IsEmpty(RelatedTable::KeyField) is often used to check for the existance of related records for the current record just before using a GTRR step to bring up a group of related records on a different layout.

          For more on Go To Related Records (GTRR) see this thread:  The Complete Go To Related Record

          • 2. Re: Copying from a template to ...

            Phil, I can always count on you.  Thanks for the quick response.

            Am I the only one frustrated with how difficult it is to do a simple thing like read tables/files?  I love FM, it is a great product.  By come on, having to have a layout to read records?  Not being able to have as many tables read with the buffers all available at the same time just seems ridiculous to me.  I know I'm new, but I've been developing software for over twenty years!  This is the first language I've seen like this.

            Ok, here are your answers:

            The Events layout is the current layout.  Basically when they change a field I look to trigger workflow events based on the event status and the type of event.

            The only relationship between the Events and Task Template is: Event_Type.  I believe that is all I need.  I want to pull in the workflow related to this specific Event (so it will look at the "Header" record Task_Template with the same Event_Type).  Then I want to copy in all the "child" records (Task_Template_Detail) to Events_Tasks.

            Thanks for the advice on GTRR.  I will add the test you provided.

            On a side note (and maybe this isn't the place).  Are you available for consulting/advice?



            • 3. Re: Copying from a template to ...

              So you have this relationship?

              Events::Event_Type = TaskTemplate::Event_Type

              What I can decipher from your script is that you start with a given Event record and use two GTRR steps to "drill down" to a set of related Template Detail records.

              You then have a loop that uses custom dialog to display one such template detail record at a time, using omit record to remove one record at a time from the found set, exiting the loop if the found set reaches 0 records or the template detail description field is empty.

              Not sure why you have that loop there. Once you've pulled up the group of detail records, do you want to create a matching set of event detail records related to the current event record? A loop is not required to do that though it can be done that way. You can also use Import records to copy a found set of records from one table to another. If creating matching detail records are what you want you can flip back and forth between the two "detail" layouts putting the data in variables, creating a new detail record copying the variable data to the new records fields and repeating for each detail record. You can also move from record to record in a loop using Go TO Record [next ; exit after last]

              I agree that the need to keep changing layouts just to reference a set of records can get awkward. However, there are design approaches that often make this unecessary or rarely needed with a database.

              With regards to your last question, check your inbox.

              • 4. Re: Copying from a template to ...

                Yes, once I pulled up the group of detail rec's I want to create matching event detail records to the current event record.

                What do you think is the best method to accomplish this?  Import or data in variables to update the new record with??

                Oh, the custom dialog boxes were just temporary (for me to make sure it was working properly).



                • 5. Re: Copying from a template to ...

                  Took your advice, implemented the code last night.  It works great!

                  One concept I was missing (and I'm sure a very basic one for everyone else) was that to go back to the starting layout after using GTRR to get the original record(s) back.  I was frustrated that whenever I read new records the prior data was not available (unless stored in variables).  I didn't realize it was as easy as "Go To Layout ....".  Duhh!

                  Thanks again for your help.