7 Replies Latest reply on Dec 1, 2015 12:11 PM by DanielShanahan

    Unflag all records


      Hi all, trying to work out a script for unflagging records in a fluid way (and to keep it quick when a database has a lot of records that may or may not be flagged).


      Flag is a field with a checkbox that lets the user choose their foundset.


      When i perform find with the attached and the results are 0 I get the attached error message. Rather than going to the next step of If Get FoundCount = 0.


      Is there a reason for this?


      I'd rather control what happens with the custom dialog and make the script move forwards but it gets stuck. I've also tried the find and restore but still it goes to the error message..


      Any ideas?




      Screen Shot 2015-12-01 at 19.22.51.png




      Screen Shot 2015-12-01 at 19.26.35.png

        • 1. Re: Unflag all records

          Hi Andrew,


          At the top of your script add


          Set Error Capture [On]


          This means that you, the developer, will capture the errors and take care of them.  FileMaker will not give the error message you're currently seeing.


          Hope that helps.

          • 2. Re: Unflag all records

            You missed the script step:


            Set ErrorCapture [on]


            That will suppress the default popup and let you control things yourself...



            • 3. Re: Unflag all records

              Also, if the number of records in your found set is a few hundred or more, consider performing this script on the server using Perform Script on Server.  It'll be much faster.

              • 4. Re: Unflag all records

                Thanks all.


                How does the perform script on server function work?


                Gone with the attached so far. Is it safe using new window and close window like this? This way it keeps the current foundset a user has on display..


                Screen Shot 2015-12-01 at 19.41.41.png

                • 5. Re: Unflag all records

                  You'll have to call Perform Script on Server (PSOS) as a sub-routine.  Simply create a new script with the script step PSOS and call "Unflag All".


                  If your script "Unflag All" is triggered by a button for event, switch that over to the new script.


                  All of this, of course, presumes you have FileMaker Server. 

                  • 6. Re: Unflag all records

                    Note: PSoS acts like a new user opening the file. It runs the Script Trigger on FirstWindowOpen. You must be sure to establish the context and found set within the script and DO NOT rely on anything in the current user's session.

                    • 7. Re: Unflag all records

                      Yes, ch0c0halic is correct.


                      In my solutions I have a server privilege set (e.g. "FMServerUser") and in the opening script check to see if FMServerUser is the one opening the file.  If so, I exit the opening script as soon as possible (but after any required settings such as global fields, global variables, etc.).


                      The other thing to do to explicitly set the context.  Modify your script by adding "Go to Layout..." so the server knows where to go.  Again, as ch0c0halic points out, the server's session is different than yours, so it won't know anything about what layout the user has open.


                      Lastly, use the "Show compatible script steps by button" in the upper right of the Script Workspace in FM 14.  Script steps such as "Show custom dialog" are incompatible and will produce an error.  If you run it on the server (PSOS), you won't need this or other non-server compatible steps, so you can delete them.