5 Replies Latest reply on Nov 8, 2011 1:10 AM by lordhellfire

    "Else if" script condition being ignored even if true

    lordhellfire

      Summary

      "Else if" script condition being ignored even if true

      Product

      FileMaker Pro

      Version

      11 Advanced

      Operating system version

      Server 2008 R2

      Description of the issue

      A script which runs with IF and ELSE IF steps sometimes ignore the true condition of an ELSE IF.

      The DataViewer tells me that the condition is 1 or TRUE when the script reaches the step, but it just continues to the next ELSE IF step to check if that is true, instead of performing the script steps within the ELSE IF statement.

      Hope you can recreate the problem and fix it :)

      Steps to reproduce the problem

      My entire setup is fairly complicated, but the basic part is this:

      I have a layout with a portal to a related table.
      The layout stores projects and the portal/related table stores SMS-messages.
      When the portal is empty, the script runs fine.
      When the portal contains sms-messages, the script fails to acknoledge the ELSE IF step even if it is true.

      The condition is VERY simple and doesn't even refer to anything inside the portal, it only checks the script parameter. It only checks if the script parameter says NEW. The button which activates the script does indeed have NEW as the script parameter.

      The IF sentence on the first IF does however refer to data in the portal and another related database. but I tried retrieving the data into $variables and testing against those. The DataViewer confirmed that the data was indeed retrieved correctly.

      Expected result

      I expected it to go into the ELSE IF sentence when the condition was true.

      Actual result

      It just skipped the ELSE IF sentence even if true.

      Workaround

      If I rewrite the script to be only IF sentences, it works fine all the time.
      - ie. change all "ELSE IF" to a "END IF" and a new IF sentence.

      This kind of defeats the purpose of having an "else if" sentence...

        • 1. Re: "Else if" script condition being ignored even if true
          philmodjunk

          We need to know more before we can replicate the issue.

          Please post your script so we can see exactly what it does.

          To post a script to the forum:

          1. You can upload a screen shot of your script
          2. You can print a script to a PDF, open the PDF and then select and copy the script as text from the opened PDF.
          3. If You have FileMaker advanced, you can generate a database design report and copy the script as text from there.
          4. If you paste a text form of the script, you can use the Script Pretty box in the Known Bugs List database to paste a version that is single spaced and indented for a more professional look to your script. (Use the HTML option and paste the text into the HTML editor.)

           

          Please note that when the IF expression evaluates as True, the Else IF will be skipped no matter what it evaluates to. That's by design. (Apologies for pointing out the obvious, but we have to rule out the obvious in issues like this before we can dig deeper.)

          • 2. Re: "Else if" script condition being ignored even if true
            DavidJondreau

            Phil, I think you've nailed it. Sounds like a misunderstanding of the the If/Else If/End If construct is supposed to accomplish. If/Else If checks for the first true evaluation, then skips all else. That's just how it works.

            • 3. Re: "Else if" script condition being ignored even if true
              philmodjunk

              We'll need to hear from the OP to be sure. If that's the case, this alternative structure might work:

              Change

              If [test 1 here]

                 Code for test 1

              Else If [Test 2 here]

                 code for test 2

              End if

              to:

              If [Test 1 here ]

                 code for test 1

              End If

              If [Test 2 here ]

                 code for test 2

              End If

              • 4. Re: "Else if" script condition being ignored even if true
                lordhellfire

                PhilModJunk> your suggestion works, but as mentioned in my original post that was also the workaround I suggested (although not very well explained)

                The issue is that it simply ignores any "true" tests under the "else if" part, even though no previous part of the if structure was deemed true)

                The problem is quite strange.

                 

                And now I found the error... You are absolutely right.

                 

                It deemed the first condition as true, because I put in an '&' instead of an 'and', which made the evaluation = 1 between two conditions in the very first IF statement where the first was false, but the second was true.

                As that IF statement had no underlying steps defined yet, I did not notice that it was in fact being performed.

                 

                You can chalk this up to an Error 40 (Error caused by individual 40 cm from the screen)... dammit..

                This will teach me to put something/anything under an IF part to determine if it gets run.

                Thanks for your help :)

                • 5. Re: "Else if" script condition being ignored even if true
                  lordhellfire

                  And the reason it worked fine regarding the portal was that the condition in the first part was linked to the portal... when empty, both tests were 0...

                   

                  IF: $scrparam="reply" & SMSdatabase relation for test only::SenderNumber ≠ $smsservice and IsEmpty(SMSdatabase relation for test only::SenderNumber)=False

                  <no steps defined>

                  ELSE IF: $scrparam="new"

                  <steps defined>

                  End IF

                   

                  The & was the mistake... it should have been an 'and'. Because the first IF did not have steps defined, I focused on the ELSE IF and could not understand why it did not evaluate it. It was such a simple test and it was true... Stupid stupid...