12 Replies Latest reply on Jan 8, 2014 12:34 PM by kaostika

    Anyway to have a script press a button?

    MSNThomas

      Is there anyway to have a script press a button?

       

      The rest of the post is a long explanation of why I want to have a script press a button, so if you don't care why feel free to skip it. If you like digging into problems read on.

       

      It's easy enough to have a script to go to the button using the object name, but I would like to activate a button within a script, since then the script that the button runs will run with all of the parameters saved in the button.

       

      I am using buttons to perform searches (which are defined by the parameters passed to the script the button runs) in order to use one list view to show several diffirent lists, kind of like a filtered portal. The script is called ButtonSearch, and its parameters are the object name of the button, the field to be searched on, and then the terms to be searched for.

       

      This works fine. There is a row of buttons, if you click on it shows just the records for that category, and you can tell which category you are looking at with conditional formatting on the button (that is why the object name of the button is put in as a parameter, since I couldn't find a way to get the button name from within the script itself).

       

      Now I want to create a layered "navigation" with tabs for categories and the search buttons for subcategories. However, if you switch from tab to tab by just clicking on the tab, you have to then click on one of the subcategory buttons before it will change the search and give you the correct records.

       

      So, I decided to switch between the tabs with buttons, because then I can use GotoObject to return to the last button pushed in each tab by saving it into a global variable. The global variable is dynamically created, and has the same name as the tab. The value put into the variable is the name of the button (subcategory) within the tab that was active when the tab was navigated away from. So first, the script (I just called it TabNavigation) saves where you were, and then it uses GotoObject. The parameter is the variable that is the same name as the tab being navigated to, which contains the name of the last button in that tab that was active.

       

      The only thing is, just going to the button isn't enough. The search script has to be rerun to have the right records showing.

       

      All of the subcategory buttons use the same script, and the search is defined by the parameters, so just calling the ButtonSearch script from the TabNavigation script won't work.

       

      One thing I am considereing is just saving the search parameters used by ButtonSearch along with the name of the button, but it would be much, much simpler if there was just a script step that let me push a button.

       

      The table I am looking at hold information on organizations, and contains all kinds of them. The three main categories are Facilities, Service Providers, and Meeting Organizers, and within each of those there are at least 6 subcategories. I know there are probably better ways to set up a navigation system (for example using virtual lists), and that the data should probably be more normalized. I plan on taking the time to redesign the database, but for now this would give me the results I need without having to create a lot of layouts or extra tables and logic.

        • 1. Re: Anyway to have a script press a button?
          ChrisPye

          ccbthomas wrote:

           

          I know there are probably better ways to set up a navigation system (for example using virtual lists), and  that the data should probably be more normalized.  I plan on taking the time to redesign the database, but for now this would give me the results I need without having to create a lot of layouts or extra tables and logic.

           

          I think that you have almost answered your own question here. Sounds like you need to normalize the data and build a better navigation system.

          • 2. Re: Anyway to have a script press a button?
            erolst

            Nomalization issues aside, let me just add that it may be better to set your search parameters by using “switches” (using global fields) and have one button, rather than many buttons where each has its set of parameters.

             

            This way a search variant is not tied to a particular object (by the parameters defined for that object), and those search parameters can be out in the open, so to speak, which may make the logic more obvious.

            • 3. Re: Anyway to have a script press a button?
              PeterWindle

              Actually, you can create a button on a layout, give the button an object name. Attach a script trigger on the button that performs script on objectenter script trigger, you can point the trigger script to the same script that the button is attached to. Within any other script, you can goto object and viola, the button behaves like you've clicked it!

              • 4. Re: Anyway to have a script press a button?
                flybynight

                Peter's solution sounds good to me.

                But another option is that rather than go to that object, just use the Run Script step, and run the same script (and pass the same params) as your button.

                If you use erolst's suggestion of having your params in global variables, you can use those in your called script params as well.

                 

                Good luck!

                -Shawn

                • 5. Re: Anyway to have a script press a button?
                  MSNThomas

                  Thats what I ended up doing.

                   

                  When the search script is called, it saves the parameters it was called with in a global variable named after the tab it is in.

                   

                  Then, the script that switches between tab just calls the search script using the variable with the same name as the tab.

                  • 6. Re: Anyway to have a script press a button?
                    nick@transmedia.co.uk

                    Hi - I may be being dim, but why would you want to cause another script to run a script via an OnObjectEnter trigger associated with a button, rather than just including a Perform Script subscript, in the original script?

                     

                    I've been trying to understand why it it now possible in FM 13 to attach a script trigger to a button at all - when obviously normally one would simply click the button to run an attached script? If anyone can provide examples of creative uses of this new "Script Trigger on the button itself", I'd be very glad to hear them.

                     

                    Thanks.

                     

                    Nick

                    • 7. Re: Anyway to have a script press a button?
                      PeterWindle

                      Nick, in terms of sheer user experience, there is no need to have a script perform upon entering a button, however... if you are a developer wanting flexibility.... what it does allow you to do is have a calling script determine which sub script is performed base on certain parameters or variables, rather than have a lot of nested if statements, for example, your calling script can be a goto object which is calculated, therefore if your parameter changes, the object that the script goes to changes, without having to change the script.

                       

                      eg:

                      a normal calling script would be:

                      If (parameter=whatever)

                      perform script (hardcoded)

                      else if

                      (parameter=whatever)

                      perform script (hardcoded)

                      end if

                       

                      whereas what the alternative calling script is:

                      set variable (target object=whatever)

                      goto object (target object)

                       

                      when the calling script goes to the object, as soon as the object is "entered" then a script can be performed.

                      • 8. Re: Anyway to have a script press a button?
                        nick@transmedia.co.uk

                        I see what you mean Peter, and I certainly appreciate you taking the trouble to reply at length.

                         

                        If I'm honest, I still feel a bit dubious, because although the Go to Object (named by variable) is efficient, surely you'd still need the 4 or 5 separate objects (buttons) somewhere on screen, to call the 4 or 5 subscripts that might be needed using an OnObjectEnter script trigger. Whereupon the inefficiency of creating those extra buttons cancels out the efficiency achieved with the GoToObject.  (Unless I've missed something important).

                         

                        What we need is a script step called Perform Script (By Calculated Name), of course!

                         

                        Regards

                         

                        Nick

                        • 9. Re: Anyway to have a script press a button?
                          PeterWindle

                          Nick,

                          I agree that there is a lot of overhead with object naming and having the script triggers on the objects. I agree that there should be a Perform Script by calculated name, I beleive there is a plug in for this...?

                          However, I am finding that

                          1. More and more I am having to create objects with names (annoying isn't it)

                          2. having buttons that are actually objects with script triggers makes for good "portability/modularity" between layouts and other solutions (given the scripts go with it)

                          • 10. Re: Anyway to have a script press a button?
                            kaostika

                            Cool.  I tested the onobject  trigger and it works well.  Sometime it is easier to have it press a button in this way.

                             

                             

                            Oreste

                            • 11. Re: Anyway to have a script press a button?
                              nick@transmedia.co.uk

                              So, you are really beginning to do this a fair bit, are you?

                               

                              Interesting - this is new to me. I literally only just noticed 2 days ago that in 13 we can have a script trigger attached to a button. And there seem to be no technique articles/demos illustrating this on the web yet.

                               

                              Thanks for your comments anyway.

                              • 12. Re: Anyway to have a script press a button?
                                kaostika

                                One place I can see this is in a subsummary report.  Some times I have a button on each body part to so something, like modify or create a related record.  If there is a summary part and the user wants to perform the script on all the records (until the next summary part) I can walk down the list and press the button for each record. It stops when it gets to the next object.  Since it is object based could be vey portable