5 Replies Latest reply on Jan 24, 2013 3:47 AM by stillsen

    Master/Slave Portal + scripted master-drop-down-list

    stillsen

      Title

      Master/Slave Portal + scripted master-drop-down-list

      Post

           hey folks,

           I am using FileMaker Pro9 and have the following db schema:

           foster_parents --< foster_parents_2_children >-- children --< grandchildren

           foster_parents_2_children::_fk_fp_id = foster_parents::_pk_id
           foster_parents_2_children::_fk_c_id  = children::_pk_id
           grandchildren::_fk_c_id = children::_pk_id

           selected_grandchild is a grandchildren table (grandchildren duplicate):

           foster_parents >--< selected_grandchild

           foster_parents::selected_child = selected_grandchild::_fk_c_id

           layout: foster_parents
           master_portal: children
           slave_portal: selected_grandchild

           Goal:

           For the master portal, there is a scripted drop-down list (value list of children's names), where the children's names are displayed. Each child shall be unique and children are handled in a different layout.
           When a (chosen) child has no foster_parents (no record in foster_parents_2_children) a new record shall be made in foster_parents_2_children with the foster_parents (current record in layout) and the selected/chosen/clicked child.
           Furthermore the childs children (grandchildren) shall be displayed in the slave portal. If the child allready has foster_parents just the grandchildren shall be displayed.
            

           so far I have two script parts, one wich triggers grandchildren update/show (thanks phil ;) ) and one which is triggered by the drop-down-list and allows to choose a child.
           grandchildren-update/show trigger:

           set field (foster_parents::selected_child; children::_pk_id)
           Commit Records/Requests[]

           drop-down-list triggers:

           go to field(children::name)
           set variable($fn; value:get(activefieldcontents))
           set variable($current_object_focus; value:get(activefieldtablename)&"::"&get(activefieldname))
           loop

           pause/resume/script[duration (seconds):0)
           exit loop if [$fn != get(activefieldcontents) or $current_object_fokus != get(activefieldtablename) &"::"& get(activefieldname)]

           end loop
            

           But I have no idea have to achieve my goal. Tried pretty much but nothing seems to work right.

           For additional input, I would be most grateful! Also for completly new approaches.

           stillsen

            

        • 1. Re: Master/Slave Portal + scripted master-drop-down-list
          philmodjunk

               This seems a bit redundant:

               go to field(children::name)
               set variable($fn; value:get(activefieldcontents))
               set variable($current_object_focus; value:get(activefieldtablename)&"::"&get(activefieldname))

               Since your are always putting the focus on

               set variable($fn; value:Children::name)

               will always produce the same result and $current_object_focus is always getting the text "Children::Name".

               but what is the purpose of this looping script? What is it supposed to do?

               Is it supposed to link the selected child record to the current Foster parent record? There's a much simpler non-scripted way to do that if you change your portal to children into a portal to the Join table linking foster parents and children.

          • 2. Re: Master/Slave Portal + scripted master-drop-down-list
            stillsen

                 Hey Phil,
                 thanks for helping out! And sorry that it takes me some time for answering.

                 The aim of the drop-down-list is to choose a child which grandchildren shall be displayed in the slaveportal.
                 The drop-down-list-script shall mainly trigger the grandchildren-display-script. But right now I explore the option to slove the following problems via this script:

                 ( allthough I believe there is a simpler way?)

                 * Every time a child('s name) is selected in the drop-down-list a new record is created for the child and foster_parents_2_child (child gets new id), even if the record for this child and its foster_parents_2_child record allready exist (in which case I just want to display them). disabling  "allow creation of records in this table via this relationsship" does not seem to help.

                 So basically I want to look up data (child and foster_parents_2_child) and display its related content (grandchildren) if there is a record telling that there is a relation between foster_parents and children or else I want to create such relation.

                  

                 Meanwhile I will explore the portal to the join table thingy.

            • 3. Re: Master/Slave Portal + scripted master-drop-down-list
              stillsen

                   I now allpied following changes:

                   The Master-Portal is foster_parents_2_children, which displays values (field) of children::name in a drop-down-list (valuelist children::name).
                   This helps for deleting the right record, since I only delete the relation.

                   But, I still have the problem that when I change the name of a child, it changes the name, allthough I want to choose another record and display the grandchildren of the selected child. Moreover I cannot assign children to current foster_parents, i.e. I cannot add a new master-table-row.
                    

              • 4. Re: Master/Slave Portal + scripted master-drop-down-list
                philmodjunk

                     It sounds like you are modifying the name field of a child record when your drop down--should you continue to use that method should be set up on a global field so that you are not modifying a child record when you select a child's name.

                     Take a look at this demo file for many to many relationships. It is linking Events to Contacts instead of Foster Parents to Children, but the principle is the same. It shows several methods for doing what you want here.https://www.dropbox.com/s/oyir7cs0yxmbn6i/ManyToManywDemoWExtras.fp7

                • 5. Re: Master/Slave Portal + scripted master-drop-down-list
                  stillsen

                       hey phil,

                       thanks a lot for the example file.
                       I'm quite impressed what you accomplish with different formats, joins and value lists.

                       allthough I didn't study most of it yet, it allready helped me to (almost) achieve what I want without scripting.

                  yes

                       thanks and cheers,

                       stillsen