2 Replies Latest reply on May 18, 2013 6:57 PM by symbister

    Looping in two tables

    symbister

      Title

      Looping in two tables

      Post

           Hi again

           I have two tables 'contacts' and 'events' linked by the join table 'contact_event' - easy

           We regularly group contacts together and assign them to an event, by a simple script to loop through a found set of contacts and write a new record in the join table with the eventID - also easy

           What I'd like to enable is a routine to group a cohort of contacts together, then group a cohort of events together, and loop through each contact, within which is a loop through each event, writing a new join record for each combination

           The set of selected events is in the form of a field containing the EventID's, chosen dynamically from a checkbox based on a TO with a conditional value list limited by date

           1. how do I capture the required events individually; and

           2. how do I loop through these within another loop to write a new join record

           as always , any help appreciated

           screen shot of work in progress might help...

      Screen_shot_2013-05-17_at_4.12.09_PM.png

        • 1. Re: Looping in two tables
          philmodjunk

               I can see how you are selecting your Events, but how do you select your group of Contacts?

               You'll need to pull up a found set of contacts records and to store your list of EventID's in either a global field or a variable for the following script to work:

               #Script should be performed from the Contacts layout

               Freeze Window
               Loop
                   Set Variable [$K ; Value: 0 ]
                   Loop
                        Set Variable [$K ; value: $K + 1 ]
                        Exit Loop If [ $K > ValueCount ( Globals::gEventIDList ) ]
                        Set Variable [$ContactID ; value: Contacts::ContactID ]
                        Go To Layout [ Event_Contact ( Event_Contact ) ]
                        New Record/request
                        Set Field [Event_Contact::ContactID ; $ContactID ]
                        Set Field [Event_Contact::EventID ; GetValue ( Globals::gEventIDList ; $K ) ]
                   End Loop
                   Go To Layout [ Original Layout] ---> must return to Contacts layout or next step won't work
                   Go to Record/Request/Page [next ;exit after last ]
               End Loop

          • 2. Re: Looping in two tables
            symbister

                 thanks Phil - once again ! works perfectly

                 I just do a simple find to select the contacts ...