1 2 Previous Next 24 Replies Latest reply on Aug 25, 2016 12:53 AM by Stigge

    Speeding a script up ?

    Stigge

      Hi

       

      Am having a seach function on my project.

      search field.jpg

       

      So when the user start typing in that box, depending on what the user types, it searches for related records.

      I have used the triggers "OnObjectKeystrokes", but its a bit slow, makes the typing to slow..

       

      The script is the following:

      Search script.jpg

       

      Is there anyone who have any suggestion on how to speed it up so it doesnt lagg every time a user type in the seach field ?

        • 1. Re: Speeding a script up ?
          Johan Hedman

          I suggest that you wait until you have 3-4 letters before you start doing your search. Then it will be a lot faster

          • 2. Re: Speeding a script up ?
            Stigge

            I like what you are suggesting..

            But how do i do that in practise ?

             

            Since i cant use another trigger can i ?

            And my script only start doing stuff enyway until "Enter", "Return" or "Tab" are pressed.

            So by adding more code to it to check the number of letters in it will only make it slower dont it ?

            • 3. Re: Speeding a script up ?
              Johan Hedman

              Use function Length() to check how long your search field is

               

              Then at the start of your script

              If ( Length (Searchfield) < 3

                   Exit Script

              End if

               

              Then your search will only execute if your search field is 3 or more letters

              • 4. Re: Speeding a script up ?
                Stigge

                Well, it was faster to type.. that is correct.. but it stopped my "Enter", "Return" and "Tab" controll :/ so the rest of the script didnt work  :/

                • 5. Re: Speeding a script up ?
                  Johan Hedman

                  Nightwing have lot of examples demos that you can look at good examples on have to handle advances techniques in FileMaker. Have a look at NightWing Enterprises - FileMaker Demos

                   

                  They have a good way of handle just what you are asking for

                  • 6. Re: Speeding a script up ?
                    twelvetens

                    By the far the best way I've seen of solving this is by using a Install On Timer script step to pause the interface whilst the field is being typed into. The amount of time you delay by can be tweaked to deal with network performance etc. Once the delay has elapsed, the filtering script can kick in (performing whatever refreshes / commits you want, and returning to the source field, int he correct position etc), before finally cancelling the On Timer Script, ready for the user to either do something else, or continue typing, which will just start everything over again...

                     

                    have a look at this:

                     

                    http://www.soliantconsulting.com/blog/2013/03/dynamically-filtering-filtered-portals

                    • 7. Re: Speeding a script up ?
                      alangodfrey

                      "So when the user start typing in that box, depending on what the user types, it searches for related records." - it reads like you are combining two techniques.

                      If you are trying to show a portal of reducing records (the list gets smaller as you type more letters) then one way is to do that by making the key field on 'this' side of the relationship a global field.  With a few other refinements it works exactly as expected, however if the portal has many potential records it can be slow to redraw after every letter, as you have found.

                      One alternative is to enter the data into that global field but only commit the record (to redraw the portal) when the user clicks a 'Go find' button.  That will be fast to type, and the one-off portal refresh will be as fast as any one of your refreshes before.

                      Your script reads like you are wanting to capture the search criterion then when a 'Go find' criterion is met (the user presses a modifier key, or as Johan suggested, have entered a certain number of characters).  That solution is fine - but needs no relationship with the field being entered.

                      Conclusion: it reads to me like you are using the fast 'capture the search and do a Find' method, but you have linked the global entry field to a relationship (unnecessary for this function), which is causing the slowdown.

                      • 8. Re: Speeding a script up ?
                        Stigge

                        well.. hard to explain.. =)

                        The layout am having this function on is a "main" page of my Telecom management project.

                        On that "Main"-page all other tables are related..

                         

                        Mainpage:

                             - User (user table, with information like business, location, manager etc)

                             - Phone numbers (we own around 10k internal phone numbers, and this table connects each nr to a user)

                             - Hardware (what phone and other hardware the user has purchased)

                             - Other subscriptions (like broadband, Mail in the phone etc)

                         

                        If i type in the seach field a name, it searches in the User table, if i enter a telephone number it seaches in my "phone Number" table, etc.. thats what i meant by saying its related..

                        I have not related the global search field to anything ofc.I just use that global field to enter the search, making it a variable and the depending on whats typed search in the "correct" (hopefully) table.

                         

                        I have thought about using a "find" button, but i dont want it. i want to implement as many "windows standard functions" as possible in this project. and searching and pressing enter is one of them.

                         

                        Using a on timer function feels risky.. lets say i put it to 2 seconds, and the user finnish his typing during this time and have already pressed enter. then my script dont run   And not having the if statement is even more risky since then it can preform the search before the user is finnished. so thats not good ether

                         

                        Am really happy about u guys trying to help me out, your all awsome. =)

                        Everything is so much easier when there is someone to argue pros and cons with =)

                        • 9. Re: Speeding a script up ?
                          twelvetens

                          Using a on timer function feels risky.. lets say i put it to 2 seconds, and the user finnish his typing during this time and have already pressed enter. then my script dont run   And not having the if statement is even more risky since then it can preform the search before the user is finnished. so thats not good ether

                           

                          - Yes, but to clarify this time function is initiated by a field level script trigger, which runs OnObjectModify, so there's no need for a 'Search'  button, or to press enter, the user just enters text, and after the defined period of time (I usually set mine at about 0.3 seconds), the script runs and the results are displayed. This is somewhat comparable to what happens when you Google something, and 'live' results are fed back to you as you type... although the algorithm in the background is a bit simpler!

                           

                          I'm a bit busy today, but I'll try and put together a demo file for you at some point...

                          • 10. Re: Speeding a script up ?
                            Stigge

                            think i understand what your saying now. no need for a demo.

                            going to test it and see =)

                             

                            Only risk that i see then is if the user stops his typing to check spelling or something.. then he needs to restart and have a blank search basicly. :/

                             

                             

                            Thank you ! =)

                            • 11. Re: Speeding a script up ?
                              alangodfrey

                              If the global field is not involved in any relationship then there is something else going on.  An 'independent' global field will not show any delay as characters are typed.

                              • 12. Re: Speeding a script up ?
                                Stigge

                                its not related. in any way.

                                All that global field does is to collect the search criteria..

                                Then in the script as you can see, it valuates to what related field it should be using for searching.

                                 

                                All the script does while typing is to check if whats beeing typed is a "Return", "Enter" or "tab" key beeing pressed.. And that couses a small delay. :/

                                • 13. Re: Speeding a script up ?
                                  alangodfrey

                                  Unless we have maybe very different standards of what constitutes a 'delay'... then Get ( TriggerKeystroke) looks like the killer.  (We don't use that, but would use a reducing portal and OnObjectModify and even though we're suing the 'slow' method it's still fast.)

                                  What happens if you change the trigger to be OnObjectModify, and check if the right-most character is one of the trigger characters?

                                   

                                  (Though I would have expected that to be the slow one.)

                                   

                                  Off to try and see if I can spot the same delay as you have...

                                  • 14. Re: Speeding a script up ?
                                    alangodfrey

                                    Tried it both ways (a test file with no records, but that shouldn't matter) and can see no delay in either case.

                                    Are you sure there isn't some other ScriptTrigger being fired?

                                    1 2 Previous Next