8 Replies Latest reply on Oct 18, 2012 11:06 AM by cbeck

    How can I use the current user in a find?

    cbeck

      I have a table "Processors" and I want to perform a find based on the account name (user name assigned in Filemaker security settings). There is a field "processors" in the table and the processor names match the account names. So, I've assigned a script step to perform a find on a button. But, I cannot figure out how to have the current user's name inserted into the find.

       

      Any ideas? I do still consider myself a novice. Any assistance would be greatly appreciated.

       

      Thanks in advance!

        • 1. Re: How can I use the current user in a find?
          BruceHerbach

          Hi,

           

          You can use the function Get ( UserName )  to get the user's name.  In a script you can do something like this.

           

          Set Variable [ $Name ; Get( Username ) ]

          Enter Find Mode []  //Pause is not checked

          Set Field [Processors; $Name]

          Perform Find []

           

          This is pseudo code,  you will have to select the actual field and may need to tweak the find.  If you are doing this in FileMaker Advanced,  you can run the script throught the debugger with the Data viewer open and see what is happening.

           

          HTH

          Bruce

          1 of 1 people found this helpful
          • 2. Re: How can I use the current user in a find?
            cbeck

            Thanks Bruce,

             

            But, I am still not able to perform a find based on the current user.  Basically, I want to run a script when a user clicks a button to open a form - so in layout mode I set up a button to perform a script - it is setup like this:

             

            Go to Layout []

            Perform Find [Restore]

                      -when I edit the find, a window pops up to "Specify Find Requests" and it has an "Action" Column and "Criteria" column.  When I edit this, it gives me a list of fields in a table and then a "Criteria" box.  I've tried entering criteria every which way possible to get it to perform a find on the "processors" field using the current user name - with no luck.  Is there another way?

             

            Thanks again!

            • 3. Re: How can I use the current user in a find?
              jbante

              You could set the acount name to a $variable in a Set Variable [] scrip step before the Perform Find step, then use that variable as the find criteria. However, I recommend an approach more like this:

               

              Enter Find Mode

              Go to Layout [...]

              Set Field [Processors::processors; Value:Get ( AccountName )]

              Perform Find []

               

              This way, you and other future developers will be able to see the find criteria without having to open the Perform Find step. Also, entering find mode before going to your target layout will improve performance a bit, since going to the target layout wont load any record data over the network until after you execute the find.

              • 4. Re: How can I use the current user in a find?
                BruceHerbach

                Hi,

                 

                The script I gave you uses the set field script step to set the Find Criteria.  So instead of having a predefined Find,  it lets the script dynamicly determine the user name and then find any records based on the current record.

                 

                This also works on a layout that doesn't have the field on it.   Although it 12 you can hide the field off the display area.

                 

                A couple of additional items.  if you turn error capture on,  it will suppress errors  messages if no records match the criteria.  You can check to see if there was an error  by using the get(lasterror).  The value will be 0 if  records are found.  Use an if statement if (get(lasterror) <> 0 .. to do something when no records are found.  You can also check for specific error codes and do something based on the exact value.  if... elseif... endif

                 

                If you need help with the script please contact me back channel

                Bruce

                • 5. Re: How can I use the current user in a find?
                  cbeck

                  Thanks jbante,

                   

                  This seems like it would work.  The problem I am having with both suggestions is that I cannot custom edit a script.  I can only choose what is in the script menu which will only let me:

                   

                       Set Field [Processors::processors] - How can I add ;Value:Get ( AccountName )] to this string?  Like I said...novice.

                   

                  Thanks gentlemen!

                  • 6. Re: How can I use the current user in a find?
                    jbante

                    When you have the Set Field [] script step selected, the "Script Step Options" area at the bottom of the Edit Script window includes a button for you to specify a calculated result. Clicking that button opens a calculation dialog. Enter "Get ( AccountName )" as the calculation.

                    1 of 1 people found this helpful
                    • 7. Re: How can I use the current user in a find?
                      cbeck

                      That worked

                       

                      Thanks again!!!!

                      • 8. Re: How can I use the current user in a find?
                        cbeck

                        Thanks Bruce,  I am sure that your solution would have worked as well had I known that I needed to specify calculations.