7 Replies Latest reply on Feb 26, 2010 5:35 AM by mmccarty

    Single button script to enter find mode and then perform find in IWP

    JohnWolcott

      Title

      Single button script to enter find mode and then perform find in IWP

      Post

      In FMPro 10, the FIND button changes to PERFORM FIND once the database is in FIND mode.  I'd like to create the same thing in Instant Web Publishing because some users don't understand they have to click on the magnifying glass to enter find mode and then after the search criteria have been entered they have to click on the "Perform Find" button on the left frame half way down.  Not very user friendly IMHP.  I would like to add a button to the layout that would combine these two steps the way the program does in the non web display.  How do I test if the database is in Find mode?  How do I change the label of the button from "Find" to "Perform Find" as the mode changes?

        • 1. Re: Single button script to enter find mode and then perform find in IWP
          mmccarty
            

          The simplist way is to put a "Find" button on your layout.  Then duplicate that layout (call it layoutCopy) and change the button to "Perform Find".  Then attach the following scripts:

           Find - Go to layout[layoutCopy]

                    Enter Find Mode

           

          Perform Find - Perform Find

                              Go to Layout (Layout)

           

          When the user clicks "Find" they are sent to the find mode but in the copy layout.  They enter their find criteria and then click "Perform Find" which sends them back to the original layout with all the found records.  The user never knows that they changed layouts, it just looks like they went in and out of find mode just like in FM.  I use this trick all the time in IWP. 

          • 2. Re: Single button script to enter find mode and then perform find in IWP
            JohnWolcott
              

              OK, that works pretty well, but I ran into the following problem.  If I enter a search criterium that doesn't exist, the script hangs.  If I click on the "Perform Find" button on the left, since I am still in find mode in the copied layout, I get a message that says no records found, but I am still in the copied layout.  How do I get the "No records found" message to display and then return to the original layout in browse mode?

              A couple of "gottcha's": be sure to use the script step "Perform Find" and not "Perform Find/Replace".  Also, the web access account is fairly restricted so I had to make sure that account had access to the new layout.

             

              I have 3 web layouts so I assume I need to make a copy of each layout and do individual scripts for each layout. 

            • 3. Re: Single button script to enter find mode and then perform find in IWP
              mmccarty
                

              Since Custom Dialogs are not possible in IWP, I use global txt fields as error messages.  Create the global text field g_error message and place it on the original layout.  Format the field so that it looks like an error message.  In the Find script add the step Set Field[g_error message=""].  Change the Perform Find script to the following:

               SetErrorCapture[on]

              Perform Find[]

              Go to Layout[ original layout]

              If[Get(FoundCount)=0]

                  Set Field[g_error message = "There are no records that meet your criteria"]

                  Show All Records

              End

               

              Now when your user clicks "Find" any error message will be erased and the user will be sent to the second layout.  Clicking "Perform Find" will send them back to the original layout.  If there find returns no results then they get an error message.

               

              Definitely DO NOT USE Perform Find/Replace!!!

               

              You will have to give your users access to the new layout and scripts.  This should be pretty simple if you are use to working with privilege sets. 

               

              Let me know if you have any other questions

              • 4. Re: Single button script to enter find mode and then perform find in IWP
                JohnWolcott
                  

                Thanks for all the information, espeically about not being able to use Custom Dialogs in IWP because I was just about to try and go down that path.  We are getting closer, but I have just spent 4 hours trying to solve how to cancel a find request in IWP.  BTW, I was going to tell you why your suggested script wouldn't work but decided to try it first, and it worked!  So thanks again for the script, which gave me the idea to take it a bit further.

                  Because I didn't want the error message to appear on the original layout, I created another layout called Find Error Message.  This layout has the global field g_error message = "There are no records that match your request.  What would you like to do?" and two buttons below it.  One button says "Modify Find Request" and the other says "Cancel Find Request."  I also wanted the user to have the option of cancelling the find on the second layout, before performing the find.  Here are all the scripts:

                 

                Find (associated button in original layout called WebContact1 in table called Fieldwork)

                  Set Field [Fieldwork::g_error message; ""]

                  Go to Layout ["WebContact1 Copy" (Fieldwork)]

                  Enter Find Mode []

                 

                Perform Find (associated button in WebContact1 Copy layout and in Find Error Message layout)

                  Set Error Capture [On]

                  Perform Find []

                  Go to Layout ["WebContact1" (Fieldwork)]

                  If [Get(FoundCount) = 0

                    Set Field [Fieldwork::g_error message; "There are no records that match your request.  What would you like to do?"

                    Go to Layout ["Find Error Message" (Fieldwork)]

                  End If

                 

                Browse Mode (associated button in WebContact1 Copy layout to allow user to cancel find before entering any search criteria)

                  Go to Layout ["WebContact1" (Fieldwork)]

                  Enter Browse Mode []

                 

                Cancel Find (associated button in Find Error Message layout.)

                  Go to Layout ["WebContact1" (Fieldwork)]

                  Enter Browse Mode []

                  Show All Records

                 

                Here are the probelms/questions:

                1)  If there is a match, everything works.  If there is not a match, you are taken to the layout Find Error Message and given the option of performing the find again (same find script which works) or cancelling (Cancel Find script).  The Cancel Find script takes you to the WebContact1 layout, but it displays 0 records (since 0 records were found).  The script step "Show All Records" doesn't seem to be working.  How can I display all records, or, even better, the found set before the find request?

                2)  Because I have 3 web pages, I have created these 4 scripts for each web page (Find1, Find2, Find3, etc.).  Is there a way to have any of the these scripts work for all 3 pages?

                • 5. Re: Single button script to enter find mode and then perform find in IWP
                  mmccarty
                    

                  1. I'm not sure why Show All Records won't work, that doesn't make sense.  One guess is maybe when you used Enter Browse Mode you enabled the "pause" feature and your script doesn't run Show All Records because it is stalled.  Another guess is that you are not on a layout with access to the table you want when the script runs Show All.  Besides that go through the scripts step by step (using the Script Debugger) and see what is happening.

                   

                  It should be possible to go back to the original found set.  Look into saved finds, you should be able to pull it off with those.  Either that or you will just have to keep information about the users previous finds in global fields or global variables then redo their find requests in the scripts.

                   

                  By the way, you don't need the Enter Browse Mode script step.  FileMaker goes back to Browse mode on its own with error capture on.

                   

                  2. The same script will work for Find and Modify Find request. However, I think the best way to simplify things is to remove the extra error message layout.   The advantage of this trick is the user doesn't know they are switching pages.  You can format the g_error message field to disappear when empty and leave it on the original layout.  The error message layout provides two options:

                                     1. Cancel Find -- But by sending the user back to the original layout and using Show All (or whatever trick you come up with to load the last found set) you've canceled the find already. 

                                      2. Modify Find -- You aren't really "modifying" because the user has to retype their find criteria.  All this is doing is giving the user the opportunity to try a different find request which can be done from the original layout. 

                   

                  If you want to keep the extra layout for style purposes then I would recommend combing all of the Find scripts into one using if/else statements based on script parameters.  The following, called User Find, is an example of type of script I'm talking about:

                  Set Error Capture[on] 

                  Set Field[g_error message=""]

                  Set Variable ($button=Get(ScriptParameter))

                  If($button=1)

                    Go to Layout[WebCopy1]

                    Enter Find Mode

                  ElseIf($button=2)

                    Perform Find

                    Go to Layout (original)

                     If (Get(foundcount)=0)

                         Set Field[g_error message = " There are no records that match your request, what would you like to do?"

                         Go to Layout[error layout]

                     End

                  ElseIf($button=3)

                     Go to Layout[original]

                      Show All Records

                  End

                  Then set all your button to the script User Find but with different script parameters.  The buttons Find and Modify Find should have script parameter 1.  Perform Find needs script parameter 2 and Cancel Find needs script parameter 3.

                  Having one script for all buttons will make life a lot simpler.

                   

                   

                   

                   

                  • 6. Re: Single button script to enter find mode and then perform find in IWP
                    JohnWolcott
                      

                    Running Script Debugger highlighted the problem with Show All Records step.  I had forgotten to assign the script to the button.  It was using my first attempt, which was simply to go to the original layout - hey, it was a long day!

                     

                    Regarding "you don't need the Enter Browse Mode script step", I assume you mean in the Cancel Find script.  You are admirably precise in your language so I tested it, and you are correct; I didn't need that step so it is gone.  I do need the Browse Mode script.  It is the only way I could think of to get out of find mode and back to the original layout.

                     

                    I have used the error message layout because of the following, which probably is due to my lack of skills here:

                    1)  I didn't know where to put the field since the layout is pretty dense, and I didn't want it to appear on top of other fields;

                    2)  I didn't know how to make it go away.  When I did a find that failed, the message appeared, and it was on every record until I did another find that I knew would return at least one record.

                     

                    The script you provided works really great!  Since I have 3 different web page layouts, I created 4 parameters, including the browse mode script, and I called them 11, 12, 13, and 14 for everything related to layout1, and so on for the other 2 layouts.  It was a nice exercise in using script parameters, but it was a pretty long script!

                     

                    Speaking of script parameters, is there a way to pass the first digit of these parameters to the error message layout scripts?  If so, I could get away with one layout.  As it is, I have 3 layouts, one for each of the web layouts since the two buttons on each error page layout have to return the user to a specific layout.  These work fine, but if I could get away with just one layout, that would be even better.

                     

                    Thanks for all your help.  It has been really educational for me, and I love seeing the buttons now do what I want them to do!

                    • 7. Re: Single button script to enter find mode and then perform find in IWP
                      mmccarty

                      I'm glad you found the problem with Show All Records.  The script debugger has saved me so many times from my own silly mistakes.  It is my favorite feature of FileMaker.

                       

                      To make the error field go away you need to delete the text in the field.  Add the script step Set Field[g_error message=""]  to your navigation scripts to and from the layout.  If the field is empty and it is formatted to be transparent then it will look like the error message disappeared.  So the user gets an error message which is erased when they do another action.

                       

                      Speaking of script parameters, is there a way to pass the first digit of these parameters to the error message layout scripts?  If so, I could get away with one layout.  As it is, I have 3 layouts, one for each of the web layouts since the two buttons on each error page layout have to return the user to a specific layout.  These work fine, but if I could get away with just one layout, that would be even better.

                       I'm not quite sure what you are asking.  Here are a couple of options:

                      1) If you have a script parameter 14 and you want to retrieve the 1 then Left(Get(ScriptParameter);1)=1 when ScriptParameter=14.  The calculation Left(text;numOfLetters) returns the specified number of letters from the text starting from the left.  For example, Left("Hello";3)="Hel".  

                       

                      2) It is possible to pass multiple parameters to a script but creating a delimited list.  For example, say I want to pass information about a person to a script aka brown hair, blue eyes, male.  I would set the script parameter equal to "brown" & ¶ & "blue" & ¶ & "male".  Then in my script to retrieve the correct parameter I use the calculation GetValue(listOfValues;valueNum) which just grabs a value out of a list. To get the person's traits, Set Variable[$hair=GetValue(Get(ScriptParameter);1)] or Set Variable[$eyes=GetValue(Get(ScriptParameter);2)] and I would have $hair="brown" and $eyes="blue".   As long as you can keep track of the order of parameters in your list this trick is really useful. 

                       

                      Hope those made sense.  Good Luck!