7 Replies Latest reply on Mar 31, 2015 1:47 PM by BobMarshall

    script to go to a record based on the account name

    soundtrackit

      Title

      script to go to a record based on the account name

      Post

      I am trying to write a script that will Get( AccountName ), then look for a record with that account name in a specific field, then go to that record.

       

      How do I do this? Thanks! 

        • 1. Re: script to go to a record based on the account name
          TSGal

          soundtrack it:

           

          Thank you for your post.

           

          One way to do this in a script is as follows:

           

          Set Error Capture [On]

          Set Variable [ $name; Get ( AccountName ) ]

          Enter Find Mode []

          Set Field [ <field you want to search> ; $name ]

          Perform Find []

          If [ Get (FoundCount) = 0 ]

             Show Custom Dialog [ "Warning" ; "No Records Found" ]

          End If

          Set Error Capture [Off]

           

          ------------------

           

          First, we set the error capture "on".  I'll explain this later...  Next, we grab the AccountName and put it into the variable $name.  Then, we enter Find mode and put the contents of the variable $name into the field you want to search and perform the find.  This is where the error capture comes in.  If no records are found, an alert usually comes up.  The error capture captures this message and displays "No Records Found".  Otherwise, the found records are displayed and we turn the error capture to off.

           

          This should get you pointed in the right direction.  If you need clarification for any of the steps above, please let me know.

           

          TSGal

          FileMaker, Inc. 

          • 2. Re: script to go to a record based on the account name
            soundtrackit
              

            Well, it's not quite working yet. Before I would always go to the first record, now with this new script, I am getting no records.. which doesn't make sense if it is truly doing a find.

             

            Each AccountName is in a field that is in a record. What could I be missing?

            • 3. Re: script to go to a record based on the account name
              TSGal

              soundtrack it:

               

              Well, I'm not sure where the problem lies.  Pull down the Records menu and select "Modify Last Find".  This will show you the contents of $name in the field you are searching.  Is this what you would normally enter?

               

              TSGal

              FileMaker, Inc. 

              • 4. Re: script to go to a record based on the account name
                soundtrackit
                   I think I found part of the problem. Whenever I perform a search for an email address, It comes up with no records found. I can search for the first part of the email address fine, but once I get to the @ symbol, I get "No Records Found". Because our account names are email addresses, this is why it came up with no results. So, how can I do the find for a full email address?
                • 5. Re: script to go to a record based on the account name
                  TSGal

                  soundtrack it:

                   

                  Thanks for the additional information.

                   

                  In order to search for special characters (@, #, $, etc.), you need to precede it with a backslash (\).  For example, if the username is a@b.com, the find would need to be a\@b.com.  Therefore, change the second line of the script as follows:

                   

                  Set Error Capture [On]

                   

                  Set Variable [ $name; Substitute (Get ( AccountName ) ; "@" ; "\@" ) ]

                   

                  Enter Find Mode []

                  Set Field [ < field you want to search> ; $name ]

                  Perform Find []

                  If [ Get (FoundCount) = 0 ]

                     Show Custom Dialog [ "Warning" ; "No Records Found" ]

                  End If

                  Set Error Capture [Off]

                   

                  ==========

                   

                  You should now be able to find the full email address.

                   

                  TSGal

                  FileMaker, Inc. 

                   

                  • 6. Re: script to go to a record based on the account name
                    gregl
                      

                    What I've found to work sometimes instead of using Substitute() to escape specific symbols, is to use the Quote() function when setting a search field. The Quote() function escapes special characters appropriately.

                     

                    Enter Find Mode []
                    Set Field [ < field you want to search> ; Quote( SomeTable::UserEnteredTextField ) ]
                    Perform Find [] 

                    • 7. Re: script to go to a record based on the account name
                      BobMarshall

                      I am having a similar problem with Get ( AccountName ).
                      At present I have just the one computer but I have set up three accounts: Admin, User, [Guest]. I was expecting Get ( AccountName ) to return a different account name depending on which user I logged in as but it will only return "admin". What am I doing wrong.