12 Replies Latest reply on Jul 14, 2012 5:15 PM by BruceHerbach

    Randomizing display of records

    barenose

      Hey everyone!

       

      Thanks so much for all of your input and suggestions in this Forum. You're all so gracious for contributing.

       

      My question today is: I have a table with quotes, etc. that I want to show as random records when a certain table opens. For example:

       

      Quote 1: This is it!

      Quote 2: No, it isn't!

      Quote 3: Come on now, y'all!

       

      etc.…

       

      I want these records to display randomly. Any ideas on how I can do it?

       

      All the best,

       

      JB


        • 1. Re: Randomizing display of records
          Mike_Mitchell

          How about a script (triggered by OnLayoutLoad) that runs a Go to Record [ By Calculation ]? The calculation might read:

           

          Floor ( Random * Get ( FoundCount )) + 1

           

          Mike

          1 of 1 people found this helpful
          • 2. Re: Randomizing display of records
            Mike_Mitchell

            There shouldn't be a loop at all. Just a single step: Go to Record .

            • 3. Re: Randomizing display of records
              barenose

              Yep, one single step. It keeps opening new windows ad nauseum. I used the OnLayoutEnter script trigger.

               

              Here's a screenshot of the script.

               

              random.png

               

              JB

              • 4. Re: Randomizing display of records
                Mike_Mitchell

                Get rid of the New Window. Every time a new window opens, it's triggering the script again.

                • 5. Re: Randomizing display of records
                  fmpros

                  Sounds like you want to popup the window with a random quote from the Quote table OVER a layout with a different table context.  If that's the case then write a small script where you 1) Freeze Window , 2) goto the Quote table layout 3) do your calc and return the quote in Exit Script, 4) grab it with Get ( ScriptResult ), 5) popup a dialog over the intended layout showing $returnedQuote.  Use FileMaker's Dialog or any 3rd party plugin will do.

                   

                  Then call that script from your desired trigger point.

                   

                  TRIGGERED SCRIPT:

                  Allow User Abort [Off]

                  Perform Script ( GetQuote )

                  Set Variable ( $returnedQuote ; Get ( ScriptResult )

                  Show Custom Dialog ( $returnedQuote )

                   

                  "UTILITY" SCRIPT: GetQuote

                  Allow User Abort [Off]

                  Freeze Window

                  Goto Layout [ QuoteTable]

                  Goto Record/Request/Page [Floor ( Random * Get ( FoundCount )) + 1]

                  Set Variable ( $theQuote ; QuoteTable::quote)

                  Goto Layout ( original layout)

                  Exit Script [$theQuote]

                   

                   

                  William O'Keefe

                  Frenel Solutions

                  1 of 1 people found this helpful
                  • 6. Re: Randomizing display of records
                    comment

                    barenose wrote:

                     

                    It keeps opening new windows ad nauseum. I used the OnLayoutEnter script trigger.

                     

                     

                    Why don't you start your script by checking if a window named "Daily Word" exists. If not, open a new window so named, otherwise select it. Then go to a random record in that window.

                    • 7. Re: Randomizing display of records
                      barenose

                      Thanks William,

                       

                      That works as expected. However, I want to return to the Main screen because it's a map. This solution leaves the dbase on the Quote screen. When I write in a return to the Main, the script keeps getting triggered.

                       

                      I made the script part of my Open script and removed the script trigger on the layout. Any other ideas?

                       

                      Thanks for your help!

                       

                      JB

                      • 8. Re: Randomizing display of records
                        fmpros

                        The problem here is my incomplete visual image of what you are trying to do.

                        I see the problem that you describe now, trying it myself makes the error obvious.

                         

                        What you need to do is take the context switching out of it.  The triggered script should

                        go like this:

                         

                        Set Variable ( $quoteList ; ExecuteSQL ( "SELECT * FROM QUOTES" ; "" ; "carriage return" ) )

                        Set Variable ( $theQuote ; GetValue ( $quoteList ; Floor ( Random * ValueCount ( $quoteList ) ) + 1 ) )

                        Show Custom Dialog ( $theQuote )

                         

                        <Edit: assuming you have one field in the Quote table, otherwise "SELECT <quoteFieldName> FROM QUOTES"......>

                         

                        I currently use a SQL plugin so I'm not yet up on the exact syntax for the FMP ExecuteSQL; my code would

                        look like this:

                         

                        epExecuteSQL ( "SELECT * FROM QUOTES" ; "rowSeparator='RETURN'" )

                         

                        Best,

                        William

                        • 9. Re: Randomizing display of records
                          barenose

                          Thanks for hanging in there with me, William.

                           

                          There isn't any native FMP SQL function, at least not that I'm aware of. What plug-in are you using?

                           

                          I wanted to try and do this without any plug-ins, if possible.

                           

                          Thanks!

                           

                          JB

                          • 10. Re: Randomizing display of records
                            fmpros

                            I assumed you were using FMP 12 which now has an ExecuteSQL function that can be used against

                            FMP tables.  If you're 11 or earlier then you need a plugin for calls against FMP.

                             

                            I use SQLRunner, a free plugin, from Dracoventions.com.  In fact I use all of Chris's plugins as a

                            "suite".  They give me at a very affordable price all the additional functionality I need.  Actually only

                            the Dialog Master and Menu Popper plugins cost (the ones I use), the other three I use are free.

                             

                            Chris is quite knowledgable, friendly and great on service and answering questions.  Over the years

                            I've used just about all the brands at one time or another and I'm not making any judgements here

                            about the others; they all seem to work as expected.  I just settled in on Dracoventions.

                             

                            SQLRunner has worked perfectly for me from day one, no matter what I throw at it.  I have also written

                            a small helper program that simplifies the management of all my SQL statements; using his plugins.

                             

                            If you're coming to Miami perhaps we can meet and discuss.

                             

                            Best,

                            William

                            • 11. Re: Randomizing display of records
                              comment

                              barenose wrote:

                               

                              I wanted to try and do this without any plug-ins, if possible.

                               

                              It is possible.

                              • 12. Re: Randomizing display of records
                                BruceHerbach

                                I took at look at the script posted earlier and if you change things slightly you can get it to work. Here is what to do.

                                 

                                1) Create a new blank layout that does not have any script triggers,  based on the same table occurence as the main layout.

                                 

                                2) Instead of using new Window use Go to Related record new window. This should open the new window on the blank layout and won't get caught in a loop.

                                 

                                3) Change layouts to the message layout and select the record

                                 

                                Attached is a picture showing the script.

                                 

                                At the end I added Pause/Resume Script [Indefinitly] step.  This will make the window modal and force it to be on top.  Add A button to the layout that does a "resume" and the Window will close and return the user to the original window.

                                 

                                I think this will do what you want with out plugins and should be fairly easy to implement.

                                 

                                HTH
                                Bruce