1 2 Previous Next 15 Replies Latest reply on Jun 8, 2011 3:30 PM by philmodjunk

    Update checkbox, but leave previous checkbox data intact?

    briananderson

      Title

      Update checkbox, but leave previous checkbox data intact?

      Post

      I'm somewhat green on filemaker pro.

      I have a field that uses a checkbox with value set that contains 7 categories. Each one of my records can have checkboxes in multiple categories. 

      What I want to be able to do is have a script update the category checkboxes if there is any text in a certain box. 
      I've tried to use a script that if a certain field has text in it, then it would check the correct checkbox just fine, but it would remove all other previous checkboxes. Is there some way that I could leave whatever checkboxes that are already checked intact and check an additional checkbox?

      Thanks!

        • 1. Re: Update checkbox, but leave previous checkbox data intact?
          philmodjunk

          Set Field [YourTable::CheckBoxField ; List ( YourTable::CheckBoxField ; "Value you want to add" ) ]

          Check box formatted fields store their selected values in a list of values separated by returns and in the order that the user clicked the check boxes, so the above script appends the new value to the end of the list.

          • 3. Re: Update checkbox, but leave previous checkbox data intact?
            philmodjunk

            While it may not cause any visible issues, the above example can add a selected value a second time to the list. You might want to modify it to work like this to avoid adding a selected value a second time. (The second copy of the value will not be visible, nor affect the function of the field as long as it is formatted as a check box field.)

            Set Field [YourTable::CheckBoxField ; If ( Not Length ( FilterValues (  YourTable::CheckBoxField ; "Value" ) ) ; List ( YourTable::CheckBoxField ; "Value" ) ) ]

            • 4. Re: Update checkbox, but leave previous checkbox data intact?
              briananderson

              Thanks for the help Phil!

              I tried to update the script using your revised script, but it seems to be removing all the data in the checkbox field. I'll keep tweaking with it. Perhaps I have typos or something else causing the issue.

              • 5. Re: Update checkbox, but leave previous checkbox data intact?
                briananderson

                I've been trying to figure this out, but apparently my lack of experience isn't helping me. Is there another script around this?

                • 6. Re: Update checkbox, but leave previous checkbox data intact?
                  philmodjunk

                  Can you post the exact script that you are using. The list function, if set up properly, keeps the step from overwriting the existing data by turning this into an append operation.

                  There are other expressions that will work, they just aren't as simple as List ( table::CheckBoxField ; "new value" )

                  YourTable::CheckBoxField & ¶ & "new value"

                  is an alternative that should produce the same result.

                  To post a script without typing it in:

                  1. You can upload a screen shot by clicking the edit link to your original message and uploading it there
                  2. You can upload a screen shot to a file share site and post the download link to a new response you post here.
                  3. You can print a script to a PDF, open the PDF and then select and copy the script as text from the opened PDF.
                  4. If You have FileMaker advanced, you can generate a database design report and copy the script as text from there.
                  • 7. Re: Update checkbox, but leave previous checkbox data intact?
                    briananderson

                    Thanks for looking at this Phil!

                    So this is what I got:

                    OnRecordLoad:

                    If [ not IsEmpty ( SUBMISSIONS::SubmissionID) ]

                    Set Field [ TITLES::Category; If ( not Length ( FilterValues ( TITLES::Category; "Submission" ) ) ; List ( TITLES::Category;"Submission" ) ) ]

                    End If

                    What happens is that it makes the correct checkbox, but when I leave the record and then come back to it, all the checkboxes are unchecked.

                    I'm pretty sure I'm doing something wrong. I just don't know what it is.

                    Thanks!

                    • 8. Re: Update checkbox, but leave previous checkbox data intact?
                      philmodjunk

                      Muy bad,

                      it should read:

                      Set Field [ TITLES::Category; If ( not Length ( FilterValues ( TITLES::Category; "Submission" ) ) ; List ( TITLES::Category;"Submission" ) ; TITLES::Category ) ]

                      • 9. Re: Update checkbox, but leave previous checkbox data intact?
                        briananderson

                        Aha! Thank you so much! Worked like a charm it appears.

                        A million times, thank YOU!!

                        • 10. Re: Update checkbox, but leave previous checkbox data intact?
                          briananderson

                          Phil,

                          Would you happen to know how to do the same exact thing, but instead of checking the checkbox in that field, it would deselect / uncheck the box, but keep the rest of the values/checkboxes intact?

                          Thanks!

                          • 11. Re: Update checkbox, but leave previous checkbox data intact?
                            philmodjunk

                            That's actually much trickier to do unless you use a custom function to remove the selected item from the list. Here's a looping script that will do it:

                            Loop
                               Set Variable [$I ; value: $I + 1]
                               Exit Loop If [$I > ValueCount ( YourTable::CheckBoxField ) ]
                               Exit Loop If [GetValue ( YourTable::CheckboxField ; $I ) = "valueToRemove" ]
                            End Loop
                            IF [$I < ValueCount ( YourTable::CheckBoxField ) // selected value was found
                                Set Field [YourTable::CheckBoxField ; Leftvalues ( YourTable::CheckBoxField ; $I - 1 ) & RightValues ( YourTable::Checkboxfield ; ValueCount ( YourTable::Checkboxfield ) - $I ) ]
                                Set Field [YourTable::CheckboxField ; Left ( YourTable::CheckBoxField ; length ( YourTable::CheckboxField ) - 1 ) ]
                            End If

                            Note: the last Set Field strips off an extra return added by the Rightvalues function. It won't hurt your checkbox field to have extra returns in it, it'll display values just fine, but I don't like to leave such extra "clutter" behind in the field to cause possible trouble in other references to this field.

                            • 12. Re: Update checkbox, but leave previous checkbox data intact?
                              briananderson

                              Thanks Phil!

                              It doesn't appear to be working with that code. Below is what I have. Let me know if I'm puttting this in incorrectly.  Thanks again!!

                              OnRecordLoad:

                              If [ not IsEmpty (SUBMISSIONS::Submission Type) ]

                              Set Field [ TITLES::Category; If ( not Length ( FilterValues ( TITLES::Category; "Submission" ) ) ; List ( TITLES::Category;"Submission" ) ;TITLES::Category ) ]

                              End If

                              If [ IsEmpty (SUBMISSIONS::Submission Type) ]

                              Loop

                              Set Variable [ $I; Value:$I + 1 ]

                              Exit Loop If [ $I > ValueCount ( TITLES::Category) ]

                              Exit Loop If [ GetValue ( TITLES::Category; $I ) = "Submission" ]

                              End Loop

                              If [ $I < ValueCount ( TITLES::Category) ]

                              Set Field [ TITLES::Category; LeftValues ( TITLES::Category; $I - 1 ) & RightValues ( TITLES::Category; ValueCount ( TITLES::Category) - $I) ]

                              Set Field [ TITLES::Category; Left ( TITLES::Category; Length ( TITLES::Category) - 1) ]

                              End If

                              End If

                              • 13. Re: Update checkbox, but leave previous checkbox data intact?
                                philmodjunk

                                The script I posted works in my demo file. The only discrepancy that I found is shown in red below:

                                If [ not IsEmpty (SUBMISSIONS::Submission Type) ]
                                       Set Field [ TITLES::Category; If ( not Length ( FilterValues ( TITLES::Category; "Submission" ) ) ;
                                                       List ( TITLES::Category;"Submission" ) ;TITLES::Category ) ]
                                Else
                                       Loop
                                               Set Variable [ $I; Value:$I + 1 ]
                                               Exit Loop If [ $I > ValueCount ( TITLES::Category) ]
                                               Exit Loop If [ GetValue ( TITLES::Category; $I ) = "Submission" ]
                                       End Loop
                                       If [ $I < ValueCount ( TITLES::Category) ]
                                               Set Field [ TITLES::Category; LeftValues ( TITLES::Category; $I - 1 ) &
                                                               RightValues ( TITLES::Category; ValueCount ( TITLES::Category) - $I) ]
                                               Set Field [ TITLES::Category; Left ( TITLES::Category; Length ( TITLES::Category) - 1) ]
                                       End If
                                End If

                                • 14. Re: Update checkbox, but leave previous checkbox data intact?
                                  briananderson

                                  Phil, Thank you thank you!  It was a bad copy and paste job, apparently. 

                                  Works perfectly now. Thank you once again!

                                  1 2 Previous Next