2 Replies Latest reply on May 24, 2013 4:56 PM by MikeTrotter_1

    Setting a FK for the PK of the current user

    MikeTrotter_1

      Title

      Setting a FK for the PK of the current user

      Post

           In my solution, I have tbl_User containing a PK_UserID and a LoginName. The LoginName is created by script at the same time the User is created in Filemaker. Therefore for any currently logged in user, there will be a match in tbl_User. What would be the best way to set the field, FK_UserID to the value of the PK_UserID in the tbl_User based on the currently logged in user?

           Am I going about this all wrong?

           Thanks in advance,

            

           Mike

            

      Relationship.jpg

        • 1. Re: Setting a FK for the PK of the current user
          philmodjunk

               What is happening at the time you want to enter this value?

               Have you just created a new record in tbl_Diversion and want that value entered automatically?

               If so, use fileOptions to have this script performed each time the file is opened:

               Freeze WIndow
               Go to Layout ["tbl_User" (tbl_User) ]
               Enter Find Mode []
               Set Field [Tbl_User::LogInName ; Get ( Accountname ) ]
               Set Error Capture [on]
               Perform Find []
               If [Not Get ( FoundCount ) ]
                 Show Custom Dialog ["Error: Log In Name not found in tbl_User"]
               Else
                  Set Variable [$$UserID ; value: tbl_User::PK_UserID]
               End IF

               Then, any time you need to enter the current user's user ID into a field, you simply need to enter the value of the $$UserID global variable.

               For tbl_Diversion, if you set up FK_UserID with this auto-enter calculation:

               $$UserID

               Any new record created in that table will automatically enter the current user's ID.

          • 2. Re: Setting a FK for the PK of the current user
            MikeTrotter_1

                 Worked like a champ! Thank you Phil.