5 Replies Latest reply on Jul 7, 2009 8:27 PM by rowie718

    Perform find based on checkbox set

    rowie718

      Title

      Perform find based on checkbox set

      Post

      Hello,

       

      I have what Im sure is a simple problem. I have a table called CPU Database. One field in the table is called "Type". This field may contain only members of a value list called "Type List". These are various types of devices....Mac Desktop, PC Laptop, Printer, etc.

       

      Now...Id like to have a filtering system for the records. My idea is to have another field in the footer called "Filter" which displays as a Checkbox Set and displays values from the same "Type List" value list. The user could select here which types they want to show in the table and click a button above it to activate the filter.

       

      I need a script now to attach to the "Activate Filter" button that will get the values of the checked boxes in the Filter field, and perform a find for records who contain any of those values in the Type field. Ive done a bunch of googling, but I cant seem to figure out how to do it. Any help would be greatly appreciated!

       

      Thanks

        • 1. Re: Perform find based on checkbox set
          LaRetta_1
            

          You should use a global text field called gFind and attach your checkbox to that (in header).  Then place button next to it with following script:

           

          If [ IsEmpty ( FindCheckbox::gFind ) ]

          Show Custom Dialog [ Message: "No Type specified. Try again."; Buttons: “OK” ]

          Halt Script

          End If

          Set Variable [ $numReq; Value:ValueCount ( FindCheckbox::gFind ) ]

          Enter Find Mode [ ]

          Set Field [ FindCheckbox::Type; GetValue ( FindCheckbox::gFind ; $numReq ) ]

          Set Variable [ $numReq; Value:$numReq - 1 ]

          Loop

          Exit Loop If [ not $numReq ]

          New Record/Request

          Set Field [ FindCheckbox::Type; GetValue ( FindCheckbox::gFind ; $numReq ) ]

          Set Variable [ $numReq; Value:$numReq - 1 ]

          End Loop

          Set Error Capture [ On ]

          Perform Find [ ]

          If [ not Get ( FoundCount ) ]

          Show Custom Dialog [ Message: "No records found."; Buttons: “OK” ]

          End If

          • 2. Re: Perform find based on checkbox set
            rowie718
              

            Awesome, that works perfectly! Thanks so much!

             

            OK....the next thing I tried to set up is a "show all" button that would clear the filters and show all records. Its basically no problem except for one little snag. Once I show all the records, I would like all the checkboxes to be checked, reflecting each Types status as "showing". How can I tell the gFind field to check all its checkboxes? I tried a few variations along the lines of "Set Field [ FindCheckbox::gFind ; ValueListItems (FindCheckbox::gFind ; Type List) ]" or using GetValue instead of ValueListItems, but I cant seem to get the value list to work as part of the syntax. I assume this is generally how you'd tell the field which values should be set within it?

             

            Thanks again.

            • 3. Re: Perform find based on checkbox set
              philmodjunk
                

              Try this:

               

              Set Field [FindCheckBox::gFind; ValueListItems( get( fileName ) ; "NameofYourValueList" )]

               

              Note: the name of your value list must be entered in quotes.

              • 4. Re: Perform find based on checkbox set
                LaRetta_1
                  

                Phil is spot on.  And the portion within quotes must match your value list name exactly or it won't work and it won't produce an error (it's one of the biggest gotchas with value lists).  So your Show All script would be:

                 

                Show All Records

                Set Field [ FindCheckbox::gFind ; ValuListItems ( Get ( FileName ) ; "Type List" ) ]

                Commit Records/Requests

                 

                Why do I commit after setting a checkbox field?  Because I think it just looks ugly with the borders box around the entire field so I always commit checkboxes when done. And DO use Get ( FileName ) instead of hard-coding your file name because if you ever change your file name, this calculation would break but if using Get ( FileName ) it will always work. :smileyhappy:

                 

                • 5. Re: Perform find based on checkbox set
                  rowie718
                    

                  Gotcha...I see how it works...ValueListItems wants the filename (which you "Get"), then the name of the list in quotes....Im getting it. This is probably a very common step in many situations.

                   

                  Thank you both, and especially you Laretta for taking the time to help and explain. I learned a lot here.

                   

                  Problem solved.