1 2 Previous Next 15 Replies Latest reply on Mar 14, 2010 11:55 AM by MikeDunglinson

    How to get the name of a Button (object)?

    MaineSteve

      Title

      How to get the name of a Button (object)?

      Post

      This would seem to be an easy thing to do, but for some reason I'm coming up with zero answers even after extensive searching.  So either I'm missing something obvious or FM Pro is lacking a rather simple script command.  Wouldn't be the first time for either situation :D

       

      I have two buttons which are labeled NEXT and PREVIOUS respectively.  The straight forward way to make this happen is to create a NEXT script and a PREVIOUS script, each of which call their own specific scripts in different files.  This would seem to be a fine solution, but I have some rather complex relationships based on the layout used which requires scripts to find/sort information in various files in order to be in a predictable state for other functions. 

       

      What I would like to do is create a single script that both buttons link to.  When that script fires it gets the name of the button, sets a variable to tell subsequent scripts to use "Goto Record/Request/Page Next" or "Goto Record/Request/Page Previous" script steps, then fires the correct script/s based on the GetLayoutName parameter (I have 8 layouts). If I can't get button names then I'm going to need two scripts in my master file (one for Next and another for Previous) and two scripts for each layout depending on the choice.  That's 18 scripts instead of 9!  Since I have other needs for button name identification I figure now is a good time to ask ;)

       

      Thanks,

       

      Steve 

        • 1. Re: How to get the name of a Button (object)?
          mrvodka
             You can pass the values as a script parameter. When you assign your script to the button, you should see an option for an optional script parameter. Then you can use Get ( ScriptParameter ) in your script to grab the value.
          • 2. Re: How to get the name of a Button (object)?
            MaineSteve
              

            AH!! So that's what I should use that field for!  Duh :)  THANKS very much for the quick response.

             

            I still think it's silly that there isn't a GET script function that will grab the current Object name regardless of what that Object is.  Seems like a pretty obvious script step to have, though I guess it isn't exactly necessary.

             

            Steve 

            • 3. Re: How to get the name of a Button (object)?
              mrvodka
                

              There kind of is.

               

              Get ( ActiveLayoutObjectName )

               

              But you have to make sure that the object is the active object.

               

              I dont think it will work properly for what your purposes are unless you plan on letting users tab to your buttons. I would stick to using the script parameters.

              • 4. Re: How to get the name of a Button (object)?
                MaineSteve
                  

                Yeah, I struggled with that one for a while because it seemed to be the obvious call to get what I wanted.  However, it doesn't work for regular buttons which are standalone.  The documentation was not very clear about that, however I found answers here that cleared things up.

                 

                To me it seems like they should just take Get (ActiveLayoutObjectName) and allow it to grab the Object Name of whatever is clicked on.  It could then serve the purpose it currently has as well as the functionality I'm looking for.

                 

                But whatever... I have my UI working correctly.  Unfortunately, there is something else wrong that I have to try and fix.

                 

                Steve 

                • 5. Re: How to get the name of a Button (object)?
                  comment_1
                     The point here is that clicking a button does not make it active (selected). This is a good thing. Otherwise you couldn't make even a simple "Copy" button, since you would lose your selection in a field by clicking the button.
                  • 6. Re: How to get the name of a Button (object)?
                    MaineSteve
                      

                    I hadn't thought of that.  Well, then back to my original suggestion which would be to have a Script Trigger called "OnClick" or something similar.  Such a Trigger would react to the click and do nothing else other than fire a script based on that event.  By that I mean not changing focus, committing records, etc.  I know the functionality can be sussed out using other things, but it isn't intuitive the way it is now.  But maybe that's just my background as a software developer creeping in :D

                     

                    Steve 

                    • 7. Re: How to get the name of a Button (object)?
                      comment_1
                         It could be a backwards compatibilty thing. Filemaker has always had the 'Button Setup…' option for a layout object. Script triggers are new in version 10 - but the file extension hasn't changed. It would indeed make more sense to put them all in the same window.
                      • 8. Re: How to get the name of a Button (object)?
                        MaineSteve
                          

                        Yup, of course assigning a script directly to a button works fine.  My point is that being new to FMP 10 I was unfamiliar with setting a parameter for the object and how to use that within my scripts to determine what object was clicked on.  Since there is a script step to get the object name it seemed logical that all I needed to do was give the object a name and call that script step.  But that only works for Tabs and fields where the focus has been shifted, which is (as you say) not what you want with a button. For something so basic I would think I wouldn't have to come here to figure out how to get it to work.  The online help should have been, uhm, more helpful 

                         

                        The long way of saying I just think they could have made it more internally consistent so that you always name an object, get the name of the object using a single call, and perform script steps based on the returned value.  Instead of having this be the method for some uses and for others require completely different behavior of setting a parameter, getting the parameter, and performing script.  The fact that I could search through the online help several times and not have this clearly explained is probably the most important issue here.  Thankfully, I have this Forum to make up for the incomplete and, sometimes, confusing language in the online help.

                         

                        Steve 

                        • 9. Re: How to get the name of a Button (object)?
                          comment_1
                            

                          Well, an object name is an object name, and a script parameter is something else. Even scripts triggering actions can send parameters. A parameter is much more flexible than a static name - it can be calculated dynamically. It would very limiting to have only the object name as the parameter.

                           

                           


                          MaineSteve wrote:

                          The online help should have been, uhm, more helpful


                          You'll get no argument from me on this one.

                           


                          • 10. Re: How to get the name of a Button (object)?
                            MaineSteve
                              

                            Yup!  Now that I know why I should use the parameter setting I'm very happy about the possibilities it offers.  But as a newbie to some of these "new" features (I've used Filemaker for 17 years, but only recently upgraded from 7.x and started getting into heavy UI based scripting recently) the documentation for creating a simple previous/next button behavior was really lacking.  A more straight forward script step, that was all encompassing, would have fixed the problem.  So would better instructions :smileyhappy:  Again, thanks for the help... very much appreciated.

                             

                            Steve 

                            • 11. Re: How to get the name of a Button (object)?
                              MikeDunglinson

                              I have  same problem but I am sorry I still do not understand the solution. I know about the optional script parameter when allocating a script to a button but what exactly do I put in there how is the button (name) passed do I use a get function in the body of the main script.

                               

                              I am on FM10 with a few years of experience but this is a new one on me

                               

                              Any further help would be greatly appreciated

                               

                              Mike

                               

                               

                              • 12. Re: How to get the name of a Button (object)?
                                comment_1

                                 


                                Mike Dunglinson wrote:

                                how is the button (name) passed


                                 

                                It isn't. The soution here is to forget about button name and use script parameter instead.

                                 


                                • 13. Re: How to get the name of a Button (object)?
                                  MikeDunglinson

                                  Thanks for the reply sorry to be so thick but I am not there yet I do not have a handle on the get parameter thing. I have 3 buttons to click on, depending on which button I click I want to enter 1 of 3 different text strings into one global field which i will insert into a "txtype" field. My script will then find all the correct transactiuon types for that report. How do I use the optional script parameter box to achieve this. Please do not think I am asking you to write my script for me but I just cannot get the general principle.

                                   

                                  Many Thanks

                                   

                                  Mike

                                   

                                  • 14. Re: How to get the name of a Button (object)?
                                    comment_1

                                    The following script will find records in category Alpha, when the button is defined to pass the string "Alpha" as the script parameter:

                                     

                                    Enter Find Mode []

                                    Set Field [ YourTable::Category ; Get (ScriptParameter) ]

                                    Perform Find []

                                     

                                    The same script will find records in category Beta, if the string "Beta" is passed as the script parameter:

                                    1 2 Previous Next