10 Replies Latest reply on Apr 28, 2011 6:53 PM by JanCarpenter

    Writing a Script with 2 conditions

    JanCarpenter

      Title

      Writing a Script with 2 conditions

      Post

      Simple question - beginner!

      I've got a file with a value list field (contains either yes, no or maybe radio buttons).

      I want to write a script that says:

      if the record has "yes" checked, omit

      OR

      if the record has "no", checked omit

      In theory, the resulting list would then only include those that have "maybe" checked (assuming all records have at least one of the buttons checked.

      Can you help me with how the script should be written?

      ps - I realize it (in this example) would be easier to just ask for those records that have "maybe" checked.  This is not really my real life problem.  I just want to know how to write a script that asks 2 questions of each record.  Hope that makes sense!

      Thanks!

      Jan

        • 1. Re: Writing a Script with 2 conditions
          RickWhitelaw

          Then describe your "real life problem" because your example indicates to me that searching for "maybe" is the best way.

          RW

          • 2. Re: Writing a Script with 2 conditions
            JanCarpenter

            Well actually I have several and they're complicated.  My basic question is how do I write a script to test for multiple or conditions - like

            if radio button equals "yes"

            or

            if field A equals "Name1"

            Is that possible?  Thanks! 

            • 3. Re: Writing a Script with 2 conditions
              LaRetta_1

              Hi Jan,

              Rick is asking for specifics because the answer could involve a find or simply looping through records but I will try to help you envision how to handle it within a script regardless ...

              You can ask two questions of same record by asking each question individually as:

              If [ checkbox = "Yes" ]
              Omit Record/Request
              End If
              If [ checkbox = "No" ]
              Omit Record/Request
              End If

              OR slightly shorter

              If [ checkbox = "Yes" ]
              Omit Record/Request
              Else If
              If [ checkbox = "No" ]
              Omit Record/Request
              End If

              Or you can ask your questions and combine them if the resulting action is the same, such as:

              If [ checkbox = "Yes" or checkbox = "No" or ClientName = "Bill" ]
              Omit Record/Request
              End If

              This 'IF/ELSE' scenario can get complex and I suggest, when writing anything other than simple few line script, you do this:

              Insert a comment in your script (which is at the bottom and produces #).  Now select it and duplicate it several times.  Now write out your thinking by double-clicking the #, something like this:

              # first I need to find all clients who live in New York
              #
              # then loop through the records and set the status field through the set depending upon Gender
              #

              Once you have written out your thinking and the sequence of what needs to happen, go back and insert your script lines within it.  I leave my 'thinking' there.  It helps me later to understand the script and it helps non-developers when viewing the documentation of how the script works.  It also helps other Developers who may need to view the script. 

              I hope this helps.  I would be happy to provide more examples if it will help you. Smile

              • 4. Re: Writing a Script with 2 conditions
                philmodjunk

                It may also just be simpler to perform a find here than use individual omit record steps, but I'm just joining in the guessing games here. Wink

                • 5. Re: Writing a Script with 2 conditions
                  LaRetta_1

                  I don't believe the issue is what result or even technique should be used, but how to run an If/Else scenario.  That's why I said whether using a find or loop or whatever, here are examples of the logic. 

                  Jan said, "This is not really my real life problem.  I just want to know how to write a script that asks 2 questions of each record. 
                  "

                  Omit Record was Jan's example so I went with it in attempting to explain how branch logic is applied within script steps of any kind. :^)

                  • 6. Re: Writing a Script with 2 conditions
                    JanCarpenter

                    Thanks to you all.  I've been unavoidably pulled from this project (just for today), but I promise you I will get back into it today or tomorrow and report back.  I can already see that this will help me enormously.  Thanks!

                    • 7. Re: Writing a Script with 2 conditions
                      JanCarpenter

                      Thank you all who posted info.  I used the answer and it worked.  I have one more question that came out of the from PhilModJunk who suggested a find command.....

                      I've got a 3 radio button field (yes, no, maybe)  I want to choose all records that are marked as maybe, but I also want to get any records that may have NO button chosen.  So, I thought that the simplest way would be to choose any that have EITHER yes or no checked and exclude them.  That way, I'll get any that have maybe checked OR any that are blank.

                      Here's what I wrote

                      Show all Records

                      Enter Fine Mode []

                      Set Field [Product::Returned?; "Yes" or "No"]

                      Omit Record

                      Set Error Capture [On]

                      Perform Find[]

                      Unfortunately, I don't get the correct results (only those records that have maybe checked).  I get all sorts of rec ords that have Yes and No checked.  Am I using Find with an "or" condition incorrectly?

                      Thanks.

                      Jan

                      • 8. Re: Writing a Script with 2 conditions
                        philmodjunk

                        Can't use an Or like that. What you are really entereing is the number 1 as your expression evaluates to TRUE (value 1) and this is what is entered as criteria.

                        While there are ways to set up an "or" type find, why do you need it here?

                        Why not this find?

                        Enter Find Mode []
                        Set Field [Product::Returned? ; "Maybe"]

                        That will find all records marked "Maybe"

                        If you want a find that drops out all records marked yes or that are marked no (records where this field is blank will now be included):

                        Enter Find Mode []
                        Set Field [Product::Returned? ; "Yes"]
                        Omit Record
                        New Record/Request  //this creates a new "request" as we are in find mode here
                        Set Field [Product::Returned? ; "Now"]
                        Omit Record

                        This illustrates how to include Or type logic in your criteria, you make separate requests for the criteria on the two sides of your "or".

                        • 9. Re: Writing a Script with 2 conditions
                          LaRetta_1

                          I would suggest multiple find requests as:

                          Enter Find Mode [ uncheck pause ]
                          Set Field [ Products::Returned ; "Maybe" ]
                          New Record/Request
                          Set Field [ Products::Returned ' "=" ]
                          Perform Find [ ]

                          Hi Jan,

                          When performing a find on the same field for multiple results (which means you want an OR condition), use multiple find requests.  The New Record/Request script-step creates a new record when in Browse and a new Find 'line' or request when in Find Mode.  You also can drop the Show All Records at the start of a find because it always searches all records.  The exception is constraining or extending found sets which is another subject.

                          • 10. Re: Writing a Script with 2 conditions
                            JanCarpenter

                            Thank you, thank you, thank you.  Works perfectly!