4 Replies Latest reply on Oct 23, 2013 6:36 PM by mikefromnewmexico

    Christmas Gift Name Draw/Generator

    mikefromnewmexico

      Title

      Christmas Gift Name Draw/Generator

      Post

           So I've been tinkering with this and I'm not sure I'm doing it right.

            

           What I need to do is have a small database of about 80 names that cannot "draw" their own name. Similar to drawing names out of a hat....make sense?

        • 1. Re: Christmas Gift Name Draw/Generator
          philmodjunk

               And the draw needs to be random, correct? And two people are not permitted to draw the same name?

          • 2. Re: Christmas Gift Name Draw/Generator
            mikefromnewmexico

                 correct. 2 people cannot draw the same name and you cannot "draw" your own name

                  

                  

            • 3. Re: Christmas Gift Name Draw/Generator
              philmodjunk

                   Define a table, People,  with at least four fields:

                   __pkPeopleID (number, auto-entered serial number)
                   Name (text)
                   RandomValue (number)
                   _fkPeopleID (Number)

                   In Manage | Database | Relationships, create a second Table Occurrence for this table and link them like this:

                   People----People|Assigned

                   People::__pkPeopleID = People|Assigned::_fkPeopleID

                   Click Ok to close Manage | Database and then add a new layout where you select Pople|Assigned in the Show Records From drop down list.

                   This script can then "draw names" for you:

                   Freeze Window
                   Go to Layout ["People" (People)]
                   Show All Records
                   Go to Record/Request/Page [First]
                   Replace Field Contents [no dialog; People::RandomValue ; Random] ---> use the calculation option. Random is a random number function
                   Go to Layout ["People|Assigned" (People|Assigned) ]
                   Show All Records
                   Sort Records [no dialog ; restore ] ---> sort on the RandomValue field
                   Go to Record/Request/Page [First]
                   Loop
                      Set Variable [$ID ; value: People|Assigned::__pkPeopleID ]
                      Go to Layout ["People" (People)]
                      IF [$ID ≠ People::__pkPeopleID]
                          Set Field [ People::_fkPeopleID ; $ID ]
                          Go to Record/Request/Page [ Next ; exit after last ]
                          Go to Layout ["People|Assigned" (People|Assigned) ]
                          Omit Record
                          Go to Record/Request/Page [First]
                      Else IF [ Get ( RecordNumber ) = Get ( FoundCount ) // on last record and trying to assign last person to themselves (unlikely but possible) ]
                           Show Custom Dialog ["Ooops! tried to assign last people record to itself, run the script again."]
                           Exit Script []
                      Else
                           Go to Layout ["People|Assigned" (People|Assigned) ]
                           Go to Record/Request/Page [Next]
                      End IF
                   End Loop

                   On your People Layout use the field tool to place the Name field from People|Assigned on it and it will show the name of the assigned person after the script has been run.