Search code examples
logical-operatorsfilemaker

Complex logic operation is not providing the right results in filemaker


I try to filter records in FileMaker using a script in which I loop through all records and filter out the ones I don't want.

I am using the following script (I am using the Dutch version, so I am not sure what the exact/correct English code is. My appology):

Go to record/page [First]
Loop
    If [
        db1::field1 = "valueA" or 
        db1::field2 = "ValueB" or 
        (db1::field3 ≠  "ValueC" and db1::field4 ≠ "ValueC")
    ]
        Omit record
    End If
    Go to record [Next; Stop after last: On]
End Loop

When running the script, I do not get the right result. For example, I do get records where: - field1 is "ValueA" - field3 is not "ValueD".

Also, when I apply the script, multiple times, the number of records that remain are getting less each time. Even when the logic is not changing!

Anyone knows what goes wrong here?


Solution

  • I suspect there is an error in your goto next record script step, that you are not showing here. Possible you are skipping an extra record if you perform a goto next record after an omit has been performed.

    Post the rest of the loop structure so that we can see the whole process.

    P.S. You don’t need parentheses in your if statement as you have only OR operators.

    EDIT: looking at your logic a bit closer, I don’t think it will do what you want, assuming I understand your need.

    Try this:

    (db1::field1 = "valueA" or db1::field2 = "ValueB")
    and
    db1::field3 ≠  "ValueC" and db1::field3 ≠ "ValueD"
    

    EDIT 2:

     Go to record/page [First]
     Loop
     If [
        (db1::field1 = "valueA" or db1::field2 = "ValueB") and 
        db1::field3 ≠  "ValueC" and db1::field4 ≠ "ValueC"
     ]
        Omit record
     Else [
        Go to record [Next; Stop after last: On]    
     ]
     End If
    End Loop