3 Replies Latest reply on Jun 27, 2012 6:01 AM by philmodjunk

    find based on drop-down

    FrankBell

      Title

      find based on drop-down

      Post

      This must be a very simple question... but I'm having trouble.

      I want to execute a Perform Find based on a field which is selected via a value list. That is, a field (SelectColor) has a dropdown based on a value list (i.e. "blue", "yellow", "red", etc.); then I want the find to find records based on that selected color. I want to set the find up as "Table::color = SelectedColor". I suspect that my problem lies in how I've defined the field with the dropdown... I set it up as a global non-stored field in the table I'm working in, on the theory that it doesn't need to be a stored field for every record. But when I try to select that field in a find statement, the field is grayed out. What am I doing wrong???

        • 1. Re: find based on drop-down
          Sorbsbuster

          You can't search on global fields as they have the same value for every record, so they cannot isolate any found set.  I think you have mixed up a couple of different ways to do what you want.

          Set the field as global, with the colour value list (as you have).

          Write a script:
          - Set Variable [$Colour ; Table::Color ]
          - Enter Find Mode
          - Set Field [Table::Color ; $Colour ]
          - Perform Find

          (Actually, this script will work by just setting the Table::Color field directly from the global, but I prefer this more universal and flexible method)

          You could attach a script trigger to the global field to run this script on modify, for example, although as a user I don't like that method as it takes me by surprise: I prefer to choose the colour and then click a button marked 'Find', which runs that script.

          • 2. Re: find based on drop-down
            FrankBell

            Hmmm... thanks! I have it set a little differently, which must be missing something...

            I have the global field (Table::SelectColor) on the layout with a dropdown based on the value list ("red", etc)

            I have a one line script ("Set Color")which says:

            Set Variable[$$SColor;Value:Trip::SelectColor]

            I set this script to run with a script trigger "On Modify", so that the variable should be set when the field is modified

            Then I have a "Find" button which has a Perform Find script which reads:

            Find Records with criteria "Table::Color[=$$SColor]

            I want the user to be able to pick a color, then have the Find button find items with that color.

            When I run that, my data viewer says Table::Color = Red (for example), and $$SColor = Red. However, I get the message that there's no match.

            Where have I gone wrong??

            • 3. Re: find based on drop-down
              philmodjunk

              Is table::color a field of type text? If it were of type number, you'd get the results you are seeing.

              This script also works for performing a find when the search criteria is entered into a global field:

              Enter Find Mode[] // clear the pause check box
              Set Field [YourTable::Color ; YourTable::SelectColor ] //this step only works if SelectColor has global storage specified
              Set Error Capture [on] // keeps "no records found" dialog from interrupting your script
              Perform find []

              Note that sorbsbuster and I don't spell out the criteria instead Enter find mode, nor in Perform find. That's a preference of many developers as we've found that this produces a script where we can see all the criteria at a glance--we don't have to open up a dialog box to check to see what criteria was used.

              Also, If your dropdown permits typing data directly into the drop down, each separate keystroke will separately trip the onObjectModify trigger. I usually use OnObjectSave for the trigger when using a drop down--saving OnObjectModify for pop up menus, radio buttons and check boxes.