14 Replies Latest reply on Feb 9, 2017 7:53 AM by philmodjunk

    How to make a script CHECK an UNCHECKED check box?

    jonathan64

      Title

      How to make a script CHECK an UNCHECKED check box?

      Post

      I have a fairly simple database which includes a check box. The value of the check box is "Yes".

       

      I am writing a script whereby it finds some records based on a given criteria (I'm fine with that part) but then I need it to take the found set and CHECK the checkbox on all of them.

       

      (Some in the found set may already have that box checked, but nevertheless I need all to be checked.) I wouldn't have thought this very hard but have been fiddling with it for weeks now and can't seem to do it. Can anyone help?

       

      Sign me,

       

      Fed Up In Florida 

       

      Thank you.

        • 1. Re: How to make a script CHECK an UNCHECKED check box?
          Sorbsbuster
            

          Welcome to the forum, jonathan64,

           

          Is the 'Replace' function (under the 'Fields' section of script steps) not exactly what you're after here?  Find your records, then add a 'Replace Field Contents' step to your script:

           

          - go to the checked-box field ('Specify target field')

          - 'Specify' the replace to be with a calculated value "Yes"

          - Select 'Perform without dialogue', and you're away.

           

          NOTE!!!: the 'Replace' function cannot be undone, so go easy...!

           

          HTH,

          Alan.

           

          PS: Okay, okay: that's the easy way.  I can hear the clamour of "Locked records!!..." already.  There is a slightly more complicated way to do it if the file is multi-user.  (The problem arises if one of the records you want to set to be 'Yes' is currently being edited by another user. It will be locked for editing by your script.)  If that scenario is liable to arise then you should write a script that goes to the first record, checks if it is locked; if not, changes the check box to 'Yes' and loops to the next record, etc, and writes a log, or simply stops and gives you a warning, if it comes across a record that it cannot update.

          • 2. Re: How to make a script CHECK an UNCHECKED check box?
            jonathan64
              

            Trying your suggestion and it's similar to what I've been trying all along, but when I add "Replace Field Contents" to the script and then choose the "Specify" button, I don't understand what to put in the "repetition" field, and if I click "specify" again next to that repetition field, it wants a calculation which must be a number, and I don't know what to put.

            • 3. Re: How to make a script CHECK an UNCHECKED check box?
              vcirilli
                

              Create a Replace Field Contents script step.

              Set Specify Target Field to your checkbox field.

              Click the Lower Specify button.  ( bottom right) 

              Click the Replace with Calculated results radio button ( third option) 

              enter "yes" in the calculation area - include the quotes.

              Check the Perform Without Dialog Checkbox.

              The script is ready. 

               

              Use a button or whatever to fire the script when you want to set all the check box fields to yes for the found set.  No Undo so be carful! 

               

               

              • 4. Re: How to make a script CHECK an UNCHECKED check box?
                Sorbsbuster
                  

                When you click 'Specify' in the 'Replace Field Contents' script step, select the CheckBox field from the list it presents.  (You may have to change the Table from the pull-down at the top of the list).

                 

                You can specify which Repetition of the CheckBox field to Replace if it is a repeated field.  If it isn't, just leave it at '1'.  Don't click on that 'Specify' button.

                 

                -----------------------------------

                A simple way to check for locked records:

                 

                To check for any records not being updated because they were locked by another user, add another step to the end of your script that sets 'Error Capture = On', repeats the original 'Find criteria', but this time also 'Omits' any records whose CheckBox is 'Yes'.  If everything ran perfectly in your script it will find none. Have an 'If Statement' immediately after the 'Perform Find' step and use the function 'Get(FoundCount)' to check if it has found zero record.  If it has, finish tidily by showing all records and going to the first record, say.  If it is not zero, then those records were not updated.  You should show a dialogue box explaining that and telling the user what to do.

                 

                If you want any clarification, just say.

                 

                Alan.

                • 5. Re: How to make a script CHECK an UNCHECKED check box?
                  jonathan64
                     I swear I've done everything stated here and it still won't check the box. Grrrrrrr. Any more advice? (PS, using FM Pro 9) Thanks.
                  • 6. Re: How to make a script CHECK an UNCHECKED check box?
                    Sorbsbuster
                      

                    Okay: either you *haven't* done exactly as suggested (don't worry, we all make mistakes), or else there is something else going on.

                     

                    Maybe, for instance, the checkbox value list *looks* like it contains "Yes", but in fact, it contains something subtly different, like "Yes[space]".

                     

                    My suggestion is to go into layout mode, right-click on the CheckBox field (assuming you're using windows) and select 'Field/Control -> Set up...'. There, check what the Value List is that the CheckBox is based upon.  You can 'Edit Value Lists...' from there, or go into 'File-> Manage ->Value Lists'.  Check that the entry for 'Yes' really is 'Yes' and absolutely nothing more.

                     

                    The reasoning is that if the CheckBox is defined to show 'Yes ' and 'No', it will hold a value of 'Yes', but display nothing.

                     

                    Another way to check if it is that that is causing the problem is to go into layout mode and duplicate the CheckBox field, but change the duplicate to be a normal edit box.  See if it appears to display 'Yes' in the records you thought you changed by the script step.  If that is the case, then we are on the right lines.

                     

                    HTH,

                    Alan.

                    • 7. Re: How to make a script CHECK an UNCHECKED check box?
                      jonathan64
                        

                      Actually I'd done that: I duplicated the check box field in the layout but formatted it as a traditional text field and yes, it does display the word YES when I check the check box.

                       

                      If it matters, the Value List is called "YES" and it contains only one custom value and that is the word YES. And I went ahead and verified as you suggested that the value is in fact set as just YES, no spaces or anything weird.

                       

                      Can you suggest anything else? I really appreciate that a total stranger

                       

                      A) Knows FM Pro since none of my friends do and

                      B) That you're willing to help.

                       

                      PS - What does HTH mean?

                      Thanks,

                       

                      Jonathan

                      • 8. Re: How to make a script CHECK an UNCHECKED check box?
                        Sorbsbuster
                          

                        We're here to help!

                         

                        Okay, let's try some other things:

                         

                        - any chance that the field is formatted to be text colour 'white'?   If you find a record that is not checked, check it, and click off the field, does it show 'Yes'?

                         

                        - If you do a 'Find' for 'Yes', does it seem to find only records with 'Yes' in the CheckBox, or are there (apparently) blanks?

                         

                        (Can you use a copy of the file when you're trying these, please?)

                         

                        - Does the data commit correctly? Do a 'Find' for those records checked as 'Yes'.  Note how many are found.  Use 'Show omitted', and confirm that they all have a blank CheckBox.  Mark one of them as 'Yes'.  Re-do the 'Find'.  Do you now have one more record than before in the found set?

                         

                        - Let's check that all the individual script steps work:

                        - Manually perform the 'Find'  that you believe the script does.

                        - Click once into the first record's CheckBox.  Do not press 'Enter', or click off the box.

                        - Do 'Replace...' and set it to be the first option, "Current contents.'

                        - When the replace is finished, do the records all look like all 'Yes'?

                         

                        If not, you've already got a problem.  If so, then the problem lies with your script.

                         

                        If you seem to have replaced the CheckBox correctly when you do it manually, can you check that in the step immediately before the 'Replace..' step in your script it takes the focus to a layout that contains the CheckBox field?  Just put in a 'Go to layout' step to be sure.  In older versions of FM scripted finds and replaces had to be done on appropriate layouts.  (Once I realised that and worked around it I never bothered to go back and check if that has changed.  But better check anyway.)

                         

                        It's going to be something simple.

                         

                        Hope this helps,

                         

                        Alan.

                        • 9. Re: How to make a script CHECK an UNCHECKED check box?
                          jonathan64
                            

                          EUREKA!

                          Mr. Watson, come here, I want you! (That's an Alexander Graham Bell reference).

                           

                          I went and cleared the entire script and starting building it over again, applying all you said and a little of my own and it worked. SO happy. Been trying for weeks.

                          Unfortunately, not sure precisely what I'd been doing wrong, but it's good now and I learned a little more about FM Pro. LOVE FMPro. Thanks for your help!

                           

                          THANK YOU THANK YOU THANK YOU.

                          • 10. Re: How to make a script CHECK an UNCHECKED check box?
                            twlack

                            Thread is old, I'm in Filemaker Pro Advanced 14 but got directed here by Google so thought others might also.

                             

                            Set Field [ yourCheckBoxField ; yourCheckBoxField & "¶Your Additional Data"}

                             

                            The data in a checkbox field is separated by carriage returns hence the need for "¶"

                             

                            The order of the lines of data does not matter.

                            • 11. Re: How to make a script CHECK an UNCHECKED check box?
                              philmodjunk

                              Yes but you need to check to see if the value has already been selected first or this code adds it to the list a second time. This can then make it impossible to clear the check box by clearing it.

                              • 12. Re: How to make a script CHECK an UNCHECKED check box?
                                twlack

                                You are right. I am running this script as a subscript. The main script finds the records I need to add the new text to so you could use an IF statement with Pattern Count > 0 to see if the new data is there already if you need to.

                                • 13. Re: How to make a script CHECK an UNCHECKED check box?
                                  beverly

                                  agreed that it should only be entered once (for counting?). however, I've never had a problem when using Substitute() to remove duplicate instances in this sort of list.

                                   

                                  Substitute( $mylist & Char(13) ; "removeMe" & Char(13) ; "" ) // clear every instance

                                   

                                  beverly

                                  • 14. Re: How to make a script CHECK an UNCHECKED check box?
                                    philmodjunk

                                    Yes but try clicking the check box to clear it when the value is in the list more than once.

                                     

                                    Better not to have a duplicate to remove in the first place.

                                     

                                    Be careful of patterncount. It can be used, but can produce "false positive" results that indicate an option was selected that was not for some value lists with some implementations of patterncount.