11 Replies Latest reply on Jul 26, 2017 7:46 AM by marksealey

    Scripted OR Find

    marksealey

      I'm using the examples kindly given by Phil and others here and here. Thanks to them!

       

      Have a pretty good prototype - but just one question, please: when I want an OR find for non-checkbox fields must I always absolutely preface each Set Field (to populate the field on the Layout with its corresponding Global, lines 46, 47) step with a 'New Record/Request' step (line 45)?

       

      Or does that one step hold good for the remainder of the script?

       

      Script snippet attached…

       

      I use either an Extend… (line 51) Step or a Perform… (line 59) Step to allow for an earlier Find's not returning results; I can't Extend an empty Found set, can I?

        • 1. Re: Scripted OR Find
          user19752

          You can extend empty found set.

          • 2. Re: Scripted OR Find
            philmodjunk

            I see a number of issues in your script:

             

            enter find mode creates the first request. You would not enter Find Mode and then immediately create a new request as that leaves the first request blank.

             

            The method you are using closely parallels manual findd. Enter Find Mode is the same as clicking the Find button and you can select New Request from the Requests menu to start a new request. Set Field does the same job as typing search criteria into fields.

             

            So you can use a manual Find process to test the details of your scripted Find.

             

            Specifically, you need to use either New Record/Request or Duplicate Record/Request to add a request each time you need to use one or a group of set field steps to criteria that describes a particular group of records you want in your found set.

             

            Note that with Extend Found Set, you don't need to use New Record/Request at all. You can use this pattern:

             

            Enter Find Mode

            specify criteria (multiple set field steps)

            extend found set

            Enter Find Mode

            specify criteria (multiple set field steps)

            extend found set

            And so forth.

            1 of 1 people found this helpful
            • 3. Re: Scripted OR Find
              marksealey

              Thanks, Phil!

               

              I decided to go back to the checkbox part of the script to see if I could teach myself OR Find scripting from scratch.

               

              Attached…

               

              I can get the two checkbox portions (lines 3 - 17 and 18 - 33) to work independently by using a 'Perform Find' script step in each case - namely at lines 15 and 30.

               

              If, though, I use 'Extend Found Set' after the second checkbox Find (e.g. line 31), I don't get the expected results when I check one (or more) values from the second checkbox set… 'Archaeology', 'Antiquities' etc by itself/themselves.

               

              What am I doing wrong, please?

              • 4. Re: Scripted OR Find
                marksealey

                Thanks, user19752!

                 

                I reply to Phil explaining that in the attached example, I do not seem to be able to extend a Found Set whenever there are no values in the first checkbox set in that example.

                 

                Do I have to test for no results in the first set and Perform Find unless the Found Set is not empty?

                 

                In the end I shall have five such checkbox sets!

                • 5. Re: Scripted OR Find
                  philmodjunk

                  I'm at DEVCON checking in with a smart phone so I can't examine your file, but multiple check box fields implies a very complex search logic.

                   

                  How do you plan on combining the criteria from the multiple check boxes in your Find requests or in a series of "extends"?

                   

                  say you have the following selected in just two such fields:

                  field 1:

                  apple

                  orange

                   

                  field 2:

                  red

                  white

                   

                  would you want to find all records where field 1 is apple and field 2 is red or white, then add to that all records where field 1 is orange and field 2 is red or white?

                   

                  If so, with just those few options selected, you need either 4 requests in one Find or one Find followed by three extends.

                  1 of 1 people found this helpful
                  • 6. Re: Scripted OR Find
                    marksealey

                    Phil,

                     

                    Thank you very much for troubling to look at this when you're busy!

                     

                    I have got a prototype to work by setting flags indicating whether or not each/any of the checkbox fields yields a result.

                     

                    Attached.

                     

                    If there are no boxes checked in the first set, then I do a Perform Find on the second (and subsequent) set(s).

                    If any box is already checked (if there are values returned in any checkbox), then I Extend.

                     

                    Each of these is in an If block. But that seems cumbersome!

                     

                    The logic will ultimately be this: five checkbox sets (each with up to a dozen or more possible values); plus a dozen or so Edit boxes (text).

                     

                    If it's good practice to use either Perform Find or Extend FoundSet conditionally depending on whether there have been any other results returned, then I think I can now do that.

                     

                    The upside is that I want ORs on all fields - regardless of value. This search has to return all records which have a value in ANY field… checkboxes OR text fields.

                     

                    What seems to be making it complicated is the order in which the script sees the fields. It could be the last field(s) on the Layout which will be used for any given search; in that case, (only) that field would need to be Perform and not (Extend)! Or the only values in the entire Find could be in the first checkbox set and, say, in the tenth text field. In which case I know I should use Perform for the first checkbox and Extend for the fifth text field.

                     

                    Etc.

                     

                    If I could always Extend (or always Perform), it'd be easier :-)

                    • 7. Re: Scripted OR Find
                      BruceRobertson

                      Attached is a file showing my suggestions and revisions for how to approach this.

                      In the first section of the script, if no criteria is entered, you need to be sure that you establish a found set of zero.

                      Later operations can extend the found set.

                      1 of 1 people found this helpful
                      • 8. Re: Scripted OR Find
                        marksealey

                        Thanks so much, Bruce!

                         

                        That's extremely helpful :-)

                         

                        The key here seems to be what you explain on lines 10 - 13: force the first Found Set to be created regardless of actual data; after that every Find operation can safely be Extend. Yes?

                         

                        I never need to test for an existing Found Set then, do I.

                         

                        And does that apply even in the case(s) when there is no guarantee that the user will search on a value in what the script sees first - usually the first checkbox set on the Layout?

                         

                        Lastly, can I continue to use the Extend Found Set script step with the text (non checkbox) fields, thereby effectively building a totally OR find?

                         

                        The time and trouble you (and Phil) are taking to help me here is very much appreciated.

                         

                        I believe I am getting close; and learning just what I need to learn as well. It's actually becoming amazingly simple.

                        • 9. Re: Scripted OR Find
                          BruceRobertson

                          Well, all of that seems fairly obvious.

                          What is less obvious is to get you to think about a few other things.

                          Especially, the behavior of checkbox fields, the value of looking at the index content, and using insert from index.

                          You may or may not want to teach your users this; but at least YOU should know about it.

                          I have purposely placed some "bad" content in a checkbox field and here I display what that looks like.

                          You can't do this (view index) on global fields.

                           

                          field index.png

                          1 of 1 people found this helpful
                          • 10. Re: Scripted OR Find
                            BruceRobertson

                            Here's a file with further mods. It provides a layout with non-checkbox fields.

                            Here, you can enter find mode in any field, do command-I (insert from index), and reveal to yourself the actual content of the field.

                            This is another facet of performing finds.

                            Knowing how to look for "properly  behaved" data is one thing.

                            Including knowing how to perform the types of searches you have asked about.

                            It is also important to know how to view and find problem data.

                            view outlet index.png

                            2 of 2 people found this helpful
                            • 11. Re: Scripted OR Find
                              marksealey

                              Bruce,

                               

                              Thank you very much indeed again for taking the time and trouble to provide such clear and helpful examples.

                               

                              They really do set me on the right road: I can see why you did everything you did; and that has taught me what to do, and how to do it in my non-prototype file now - which is just what I hoped for when asking these questions.

                               

                              I'll work on it in the next few days and come back if I have any questions, which I ought not to have because your scripts and comments are so transparent!

                               

                              Thanks again :-)

                               

                              Ideally, I'd like to be able to loop through all the non-checkbox fields and put the find steps inside such a loop; there's no way to do that, is there?