1 2 Previous Next 15 Replies Latest reply on Jun 7, 2012 5:14 PM by m.bodily.consulting

    Using a checkbox to trigger script

    m.bodily.consulting

      In the Checkout Book layout I am trying to get this checkbox (when checked) to create a new record in the Checkout Log layout. And when unchecked, it will delete the record created in the Checkout Log layout.

      The problem is that WHENEVER I click in this box (to check or uncheck) the Remove from Loans script runs (see script below). So if the box is already unchecked and I try to check it (to create a new record), the custom dialog (part of Remove from Loans script) pops up.

       

      Here are the 2 scripts. (FYI the checkout box displays data from Master::AssignCheckout, there is only one box to check called "yes"):

      1. Checkout_AssignCheckbox

      • Go To Layout ["Checkout Log" (Checkout)]
      • If [Master::AssignCheckout = "yes"]
        • Set Variable [$patronID;Value:Patrons::zpatronID]
        • New Record
        • Set Field [Checkout::patronID; $patronID]
        • Commit Records
      • End If
      • Perform Script ["Remove from Loans"]
      • Go to layout [original layout]

      2. Remove from Loans

      • Beep
      • Show Custom Dialog ["Are you sure you want to remove this book..."]
      • If [Get ( LastMessageChoice ) = 1] <<1=Cancel>>
        • Exit Script []
      • End If
      • Delete Record [No dialog]
        • 1. Re: Using a checkbox to trigger script
          Mike_Mitchell

          If I understand your question correctly, you want the "Remove from Loans" part to run only if the checkbox is UNchecked, right?

           

          If so, then just do this:

           

          If [ Master::AssignCheckout = "yes" ]

            (do all the same stuff)

          Else

            Perform Script ["Remove from Loans"]

          End If

          Go to Layout [original layout]

           

          Should do what you need.

           

          HTH

           

          Mike

          • 2. Re: Using a checkbox to trigger script
            m.bodily.consulting

            Mike,

            I tried this order of steps too. I think my problem is in the "If" step....I wonder if there is a calculation specific to checkboxes...

            • 3. Re: Using a checkbox to trigger script
              Stephen Huston

              How do you have the script trigger set up on this field: On Enter, On Modify, On Exit ?

               

              I think it should be On Modify, and the entire process to run should be in one script, not in a subscript. That way you can control the Exit Script setting, which needs to be set to Exit Script [1, true] to commit the change to the field when you exit the triggered script.

              • 4. Re: Using a checkbox to trigger script
                m.bodily.consulting

                OnObjectValidate. Then I tried it on ObjectModify...this didn't fix the problem either.

                • 5. Re: Using a checkbox to trigger script
                  Stephen Huston

                  The trigger action alone won't fix it.

                  I think it should be On Modify, and the entire process to run should be in one script, not in a subscript. That way you can control the Exit Script setting, which needs to be set to Exit Script [1, true] to commit the change to the field when you exit the triggered script.

                  On Modfiy is actually executed before the change can be committed. That is why you must handle to Exit Script setting as well, and you cannot do that if it ends in a sucbscript.

                  • 6. Re: Using a checkbox to trigger script
                    DieterBothof

                    Hi

                     

                    I do nearly the same but slightly different: I do not use the triggers instaed I define the checkbox itselfe as key. I add the change of the field value in the script:

                     

                     

                    If [ Master::AssignCheckout = "yes" ]

                       SetField [Master::AssignCheckout] = ""

                       Perform Script ["Remove from Loans"]

                    Else

                      SetField [Master::AssignCheckout] = "yes"

                      Set Variable [$patronID;Value:Patrons::zpatronID]

                      New Record

                      Set Field [Checkout::patronID; $patronID]

                      Commit Records

                    End If

                    Go to Layout [original layout]

                     

                    Regards Dieter

                    • 7. Re: Using a checkbox to trigger script
                      Stephen Huston

                      Yes, making the field behave as a button avoids the issues of script triggering and Exit Script results. Probably much cleaner, but it does require that you remove the field from the tab order and make the user click directly on it.

                       

                      (You can put the button itself in the tab order, but tabbing to and executing buttons from the keyboard seems to be confusing for many users.)

                      • 8. Re: Using a checkbox to trigger script
                        taylorsharpe

                        Checkboxes use a value list to determine what is getting put in the field when you click the box.  Make the checkbox a little wider and see what word is getting checked when you click on it.  That is the word you have to use to set the "If" statement. 

                        • 9. Re: Using a checkbox to trigger script
                          m.bodily.consulting

                          Dieter,

                          I took off the script trigger and changed the checkbox to a button. But now it acts JUST as a button in that the box will not check (it is stuck on UNcheck) and so the "Remove From Loans" script won't run at all...because AssignCheckout is never "yes". This is the script:

                          Script_assigncheckbox.png

                          • 10. Re: Using a checkbox to trigger script
                            m.bodily.consulting

                            I only have 1 value option in the check box, it is "yes" (no caps). I am simply using the checkbox to indicate whether or not the record is selected or not. I thought this was the easiest way to determine the selection...but other suggestions are welcome

                            • 11. Re: Using a checkbox to trigger script
                              taylorsharpe

                              In the Else section, switch the first two lines so that you change the value of the AssignCheckout before you change layouts.  I'm not sure if changing layouts changes your context, so it is safer to change it before switching layouts.  Try that and let me know. 

                              • 12. Re: Using a checkbox to trigger script
                                beverly

                                I do this too, m. Although, I tend to use a "1" and the field is NUMBER instead of TEXT. That way I can "count" the ticks (checks) if needed.

                                 

                                If it's a number field, you can format it on the layout as BOOLEAN. This allows you to "label" it with "Yes", even if the "value" is 1.

                                 

                                Another + to using a number is the "toggle" (if scripted) can be this calculation:

                                     Set Field[ numberField; abs(numberfield - 1)  

                                This allows it to be blank or 0 to start and it will toggle back and forth between 0 and 1.

                                 

                                Beverly

                                • 13. Re: Using a checkbox to trigger script
                                  DieterBothof

                                  Hi

                                   

                                  Switch the two lines

                                   

                                  Bildschirmfoto 2012-06-06 um 10.43.49.png

                                   

                                   

                                  and it should be done.

                                   

                                  Have you read Beverlys hints below? They are not from the bad ones. Setting the checkbox fieldtype to number is a good recommendation.

                                   

                                  Best Regards Dieter

                                  • 14. Re: Using a checkbox to trigger script
                                    m.bodily.consulting

                                    I appreciate everyones help. And all my scripting/checkbox questions might seem ambiguous. So I want to attach a copy of the file I'm working on https://dl.dropbox.com/u/82438691/Laiberry_Copy060612Copy.fp7 (follow this link to my dropbox).

                                    Here is how you get to the layout(s) I'm talking about:

                                    1. Upon opening you will see a dialog box. Proceed to "Circulation Desk" (button at top right of window).
                                    2. In step 1, "Select Patron" from drop-down
                                    3. Click the Checkout Book(s) button
                                    4. This will open a window to the "Checkout" layout, you have to search for a book (i.e. type in "tree", this will find 21 records)
                                    5. Click on the checkbox in one of the book records (left-most field)
                                    6. NOTICE: the dialog pops up even though the checkbox IS NOT checked. To reiterate, this dialog should only pop up when the box IS checked, and I attempt to uncheck it.

                                    I have more problems than the checkbox alone, if you are willing to help me further also see:

                                      7.  Open a New Window, go to "Checkout Log" (in the MB folder) --this is the layout that [should] hold all records created via checking the checkbox.

                                      8.  NOTICE: a new record is not added to the "Checkout Log" each time a new checkbox is checked. The bookID field does not auto populate with the bookID

                                           (found on the Master table) as it should

                                      9.  NOTICE: in the "Checkout Book" layout the CheckoutDate field (and the "Today" button) reads <Unrelated Table>. What should my table relationships look like

                                           to fix this?

                                    1 2 Previous Next