4 Replies Latest reply on Nov 13, 2012 10:11 AM by philmodjunk

    How do you tell a script to check a box?

    WillRetherford

      Title

      How do you tell a script to check a box?

        • 1. Re: How do you tell a script to check a box?
          davidanders

               Do you have more than one checkbox in the field?

               SetField(CheckboxField, "CheckboxName") will check ONE item.
               SetFIeld(CheckboxField, "") will uncheck ALL items.

               For more than one checkbox, it gets a little bit trickier. The value of the field is actually the value of each checked box. So you have to play with the substitute command to get the value out. For example:

               To check a checkbox when there is more than one:
               SetField(CheckboxField, "CheckboxFIeld & "|P" & CheckboxName)
               (the |P is the paragraph marker , not the letter P)

               To uncheck:
               SetField(CheckboxField, Substitute(CheckboxField, CheckboxName, ""))

          • 2. Re: How do you tell a script to check a box?
            philmodjunk

                 To select a check box where there is more than one check box value, I suggest:

                 Set Field [ YourTable::CheckBoxField ; If ( IsEmpty ( Filtervalues ( YourTable::CheckBoxField ; "ValueToSelectHere" ) ; List ( YourTable::CheckBoxField ; "ValueToSelectHere" ) ) ]

                 This only appends the value to the list if it is not already selected. (adding duplicate values to the field won't keep it from functioning correctly, but I prefer not to "clutter" the field up that way.)

                 Be careful using:

                 SetField(CheckboxField, Substitute(CheckboxField, CheckboxName, ""))

                 to uncheck a field. If you have one check box value named "applesauce" and another named "apple", SetField(CheckboxField, Substitute(CheckboxField, "apple", ""))

                 will uncheck both check boxes and leave "sauce" as a hidden value in the field. (The check boxes will hide the presence of any value in the field that doesn't match a value in your value list unless you remove the check box format, returning it to "Edit Box" format.)

                 Set Field [ Yourtable::CheckBoxField ; Substitute ( ¶ & YourTable::CheckBoxField & ¶ ; ¶ & "ValueToClearHere" & ¶ ; ¶ ]
                 Set Field [ YourTable::CheckBoxField ; Middle ( YourTable::CheckBoxField ; 2 ; Length ( YourTable::CheckboxField ) - 2 ) ]

                 will avoid that possible complication.

                 The second set field step strips out the added returns at begginning and end of the remaining list of values added in the first step.

            • 3. Re: How do you tell a script to check a box?
              WillRetherford

                   I am just trying to check one field with the script and setting it to SetField is not working. Which step am I missing?

                   There is no "CheckBoxField" from what I can see.

              • 4. Re: How do you tell a script to check a box?
                philmodjunk

                     You would replace "checkboxField" with the name of the field you have set up with the check box format on your layout.