1 2 Previous Next 16 Replies Latest reply on Dec 8, 2016 8:22 AM by embeco

    Test For An "OR" Condition

    embeco

      I want to find all records that contain a text string in field 1 OR field 2 with scripts. I can set up a Specify Find Request looking for records that contain a text string in Field 1 AND Field 2 but I cannot figure out how to select record via an OR condition.

      PERFORM FIND where Field 1 = "Text 1" OR Field 2 = "Text 1"

        • 1. Re: Test For An "OR" Condition
          David Moyer

          Hi,

          start outside of a script ...

          -enter find mode

          -type Text 1 in Field 1

          -create a new request (ctrl-n) same as creating a new record in browse mode

          -type Text 2 in Field 2

          -keypad Enter to perform the find

           

          hope that helps

          • 2. Re: Test For An "OR" Condition
            philmodjunk

            Use two requests instead of 1.

             

            Enter Find mode [ ]

            Set field [YourTable::field1 ; "Text 1" ]

            new record/request

            Set field [YourTable::field2 ; "Text 2"]

            Set Error Capture [on]

            Perform Find [ ]

             

            You can also do this with stored criteria by also generating two requests, but I prefer to do it this way as I don't have to open extra dialog when I review the script at a later time and need to see what criteria was used.

            • 3. Re: Test For An "OR" Condition
              David Moyer

              let me add more to this pile-up.  Here's the scripted version ...

              • 4. Re: Test For An "OR" Condition
                philmodjunk

                That would be the scripted version for stored criteria and not something used in my script example--just to be clear. (Scraping your peanut butter off my chocolate once again! )

                • 6. Re: Test For An "OR" Condition
                  RickWhitelaw

                  I believe the new record/request step would be unnecessary.

                  • 7. Re: Test For An "OR" Condition
                    philmodjunk

                    It's necessary when you want all records with the value in field 1 combined with all records that have the value in field 2.

                     

                    There is an alternative approach, however, You can perform a find specifying the criteria for field 1, then extend the found set specifying criteria for field 2.

                    • 8. Re: Test For An "OR" Condition
                      embeco

                      Thanks for your reply.

                       

                       

                       

                      I'm doing that now with Extend Found Set but the problem is when there are

                      no records found with the first find (Field 1), it pops up with "No records

                      found" message when there are records that can be found with the Extend

                      Found Set since I am using another field to search on. I can't find a way of

                      turning off the "No records meet the first find criteria." If I could just

                      test for records in both fields with a Specify Find Request. If I can write

                      an AND request why can't I write an OR request?

                       

                       

                       

                      Steve

                      • 9. Re: Test For An "OR" Condition
                        embeco

                        Thanks for your reply,

                         

                         

                         

                        I'm not creating new records.

                         

                         

                         

                        Steve

                        • 10. Re: Test For An "OR" Condition
                          embeco

                          Thanks for your reply.

                           

                           

                           

                          I am currently using a PERFORM FIND followed by EXTEND FOUND SET. The

                          problem is that if there isn't any records found using the first filed, the

                          system sends out a "No records matching your find request." even though the

                          extend found set did find records using the second field. If I could turn

                          off the "NO RECORDS message, that would work for me.

                           

                           

                           

                          To Filemaker: If I can write a Specify Find Request searching two fields

                          with AND find why can't I write one with an OR.

                           

                           

                           

                          Steve

                          • 11. Re: Test For An "OR" Condition
                            embeco

                            David,

                             

                             

                             

                            I didn't get the scripted version.

                             

                             

                             

                            Steve

                            • 12. Re: Test For An "OR" Condition
                              keywords

                              Steve, as already pointed out, if you want a single find to be an OR find you must use two separate Find Requests. In essence your script will have these steps:

                              1.     Enter Find mode

                              2.     Enter your first Find criterion—you do this using Set Field, as per script example posted by Phil

                              3.     Select the New Record/Request script step—NOTE: because you are using this script step in Find mode it is a new REQUEST, not a new record

                              4.     Enter your second Find criterion—as per step 2

                              5.     Perform the Find

                              NOTE: If you entered the two criteria (steps 2 and 4) without step 3, FM would search for fields that match BOTH criteria, in other words an AND search. With step 3 inserted between them, FM will search for records that match the first criterion and THEN search for records that match the second criterion, in other words an OR search. In effect, this is what you do manually if you use the Extend option, but this is the way to script it.

                               

                              That is more or less exactly as proposed already by Phil, but with some explanatory notes added.

                              • 13. Re: Test For An "OR" Condition
                                David Moyer

                                I'm still confused by your needs.

                                I can set up a Specify Find Request ....

                                Are you wanting to use a script, or a saved find?  If you want a script, you can use the methods mentioned in posts 1, 2 and 12.  You'd be creating a new Find Request, not a new record.

                                Or, if you want to enclose your OR into a "single" script step (but with setting variables), you can use the Perform Find script step ...

                                • 14. Re: Test For An "OR" Condition
                                  philmodjunk

                                  Set Error Capture [on]

                                   

                                  Will keep the error message that no records are found from popping up. So you can add that to your current script after the first Perform Find and your current script should then work as expected but without that error message if the first find fails to find any records.

                                  1 2 Previous Next