7 Replies Latest reply on Sep 27, 2012 10:02 AM by schamblee

    1 Button - 2 Scripts?

    Dekade

      Title

      1 Button - 2 Scripts?

      Post

            

      Question: Can 1 button function as a switch (so to speak) by performing 2 scripts?

            

      Here is my reasoning:

            

             
      1.           I have a “MAIN” database – ‘original layout’ with a “Selected Categories” portal as a join
      2.      
      3.           Each row of the “Selected Categories” portal represents a record from a “Categories” database           
                         
        1.                     There may be 50 {+ or –} rows thus representing 50 {+ or -} records from the “Categories” database
        2.           
             
      4.      
      5.           A “Selected Categories” portal row consists of the following:           
                         
        1.                     A related “Categories” field called ‘Category Topic’
        2.                
        3.                     A “Selected Categories” field called ‘Topic Count’; the ‘Topic Count’ field is to show how many different total records in the “MAIN” database have used each “Selected Categories” rows’ specific ‘Category Topic’.
        4.                
        5.                     A “MAIN” database button – Described in 4) as follows:
        6.           
             
      6.      
      7.           The row button I hope could function as follows:           
                         
        1.                     Click 1st time – perform a script that creates a “Selected Categories” record with info about the portal row                     
                                     
          1.                               The created record will fill in a field in the “Selected Categories” database with the respective portal rows’ related ‘Category Topic’.  (lets say the topic is – DOGS)
          2.                          
          3.                               Then also in the “Selected Categories” database there is a ‘Total Usage’ field that shows how many records total in the “MAIN” database are there that have chosen DOGS
          4.                          
          5.                               The new ‘Total Usage’ field count is then displayed in the “Selected Categories” portal row ‘Total Usage’ field.
          6.                          
          7.                               The button now turns BLACK in color; the button was originally CLEAR in color.
          8.                     
                         
        2.                
        3.                     Click 2nd time – perform a script that erases the record created by the first click and turns the button color back to CLEAR; indicating that my mind has been changed about associating DOGS to the given “MAIN” record.
        4.           
             

            

           Summary:

            

           Multiple rows can be selected in the “Selected Categories” portal for each “MAIN” database record. Thus the portal will display via the BLACK colored buttons which ‘Category Topics’ have been associated with the respective “MAIN” database record.

            

           So, that’s what I want to accomplish with one button.

            

           I’m fairly certain (but not totally) that I can create all necessary script lines except for the lines that would make the button perform 2 different scripts. Those lines are where I need the help. However, any ‘all encompassing lines’ help would be greatly appreciated.

            

      If one button cannot function the way that I am wanting then what might be the alternative solution? Maybe two buttons – one button would create the record and one button would erase the record? How would I make the create button turn black in color and then both buttons to be clear colored to erase the record? I think the erasing would be a calculation but I can’t perceive what the calculation would be.

            

           Thanks for any input,

            

           Dekade

            

            

        • 1. Re: 1 Button - 2 Scripts?
          schamblee

               Yes.  Use global variable.   Set variable when layout load.  (set variable $$click=1)

               Then in your button script

               if $$click=1 then

               ....

               set variable $$click=2

                

               else

               ------

               set variable $$click=1

               endif

                

          • 2. Re: 1 Button - 2 Scripts?
            Dekade

                 S Chamblee,

                 I'm sorry but your reply makes no sense at all. It seems as though there is a lot in your head that you know about the solution but that info has not come out in a way that makes sense to me. Please do not be offended by this reply.

                 Dekade

            • 3. Re: 1 Button - 2 Scripts?
              philmodjunk

                   The global variable $$Click keeps track of whether this button was previously clicked. You take your two scripts and make one script out of it, putting the tasks you want performed when it's the first click above the Else step and the tasks you want performed on the second click below the else step.

                   But since you have rows in a portal, that may not work. I think you need to keep track of whether or not this is the first mouse click for each row in your portal.

                   If so, S Chamblee's method still does the job if you substitute a field added to the portal's table for the global variable.

              • 4. Re: 1 Button - 2 Scripts?
                Dekade

                What does Chamblee mean by "Set variable when layout load."?

                I also am not grabbing his (relative to what your are saying) I understand the "...." but I don't understand how and or why the"set variable $$click=2" BEFORE the Else step:

                     Then in your button script

                     if $$click=1 then

                     ....

                     set variable $$click=2

                      

                     else

                     ------

                     set variable $$click=1

                     *******************************************************

                     Per: "I think you need to keep track of whether or not this is the first mouse click for each row in your portal."

                     I do intend to have this 2 way button on each row of the portal. Is that what you mean?

                      

                • 5. Re: 1 Button - 2 Scripts?
                  philmodjunk

                       First, you'll need to use a field and set field in place of a variable and Set variable. That way you can keep track of the button status on each row in your portal.

                       "Set Variable with Layout Load" refers to using the OnLayoutLoad script trigger to initialize the button click status when you first access the layout. You won't need to do that with the individual fields that I am suggesting.

                       Updating the original logic framework for this script:

                       If [Portaltable::click=1]

                       ....

                       set Field [Portaltable::click ; 2 ]

                        

                       else

                       ------

                       set Field [Portaltable::click ; 1 ]

                       End If

                       The two Set field steps (and the original set variable steps) keep track of whether this is the "first" or "second" mouse click. They update the value so that the next mouse click on the same record performs whichever section of the script was NOT performed the previous time.

                  • 6. Re: 1 Button - 2 Scripts?
                    Dekade

                         Okay. I will try to work this out. I will probably be back later.

                         Dekade

                    • 7. Re: 1 Button - 2 Scripts?
                      schamblee

                           Thanks Phil.

                           Sorry, I had other work going on.