13 Replies Latest reply on Dec 2, 2011 9:13 AM by LyndsayHowarth

    Scripting

    Jason_Farnsworth

      Hello all,

       

      I have a need in a script to skip a few lines if

       

      If [Get ( FoundCount ) = 0] comes back true I need to just move down a few lines in the script.

       

      How would I go about skipping a few lines of the script?

       

      Thanks,

       

      Jason

        • 1. Re: Scripting
          paulspafford

          If

          … insert those few script steps …

          End If

           

           

           

           

          --

          Paul Spafford

          FileMaker Database Superhero,

          Spafford Data Solutions

           

          Tel: 613 838 9956

          www.paulspafford.com

          www.ottawafilemakerdeveloper.com

          www.fmlayoutmode.com

          www.fmscripts.com

           

          FileMaker User Group in Ottawa:

          www.meetup.com/fudgeo

          • 2. Re: Scripting
            shearn

            Make your If calc to be:

             

            If [ not Get (FoundCount) = 0 ]

              the step to skip

              the step to skip

              the step to skip

            End If

             

            If there are steps to execute only if there are no records, insert an Else after the skipped steps.

            • 3. Re: Scripting
              Jason_Farnsworth

              I get the script IF Statement, I dont know what is the "the step to skip" what would the syntax look like to for that line.

               

              Thanks

               

              Jason

              • 4. Re: Scripting
                shearn

                Hi Jason,

                 

                These are the steps that you want to skip when there are no records. The IF tests if there are records rather than if there aren't so the "steps to skip" are the steps you do want to execute when there are records in your found set.

                • 5. Re: Scripting
                  Jason_Farnsworth

                  Ahh,

                   

                  So it might be a little more complex than a simple skip then I have severals ifs running and they are in a loop.

                   

                  script.PNG

                   

                  So at the top I have disabled the if line that catches the no record.

                   

                  What I am trying to do is that if the found count is 0 I want to move to the bottom on top of the first loop?

                   

                  When you create an IF in the script it also creates and ENDIF automaticly, does it then tie the two together? Right after the IF I have to more IF's.

                   

                  Thanks,

                   

                  Jason

                  • 6. Re: Scripting
                    shearn

                    Not sure I understand where in your script you want to skip to but you could enable your IF and use "Get (FoundCount)>0" (which is the same as 'not Get(FoundCount)=0' but clearer). The END IF line would go above the line you want to skip to (the first loop is line 1 so I don't see how you want to go to 'the bottom on top of the first loop'). You'll notice that the other IF/END IF lines will automatically get indented when you move an END IF past them. FileMaker doesn't tie them together but it knows that they operate as a pair so it figures out which END IF goes with which IF.

                     

                    Btw, you could clean up those 2 IF's by using IF / ELSE IF / END IF. Since it's not possible for your script parameter to be both "Primary" and "Secondary" at the same time there no need to process both steps each time. So it would become:

                    IF [ Get (ScriptParameter)="Primary"

                       Constrain FS

                    ELSE IF [ Get (ScriptParameter)="Secondary"

                       Constrain FS

                    END IF

                    • 7. Re: Scripting
                      Jason_Farnsworth

                      Ok I see that the ENDIF and the If are indenting and looking ok, when I click to save the script it tells  "Invalid Script Step"

                       

                      Thanks I did clean up the Next IF's that works well.

                       

                      script1.PNG

                       

                      Why would I be getting the error?

                       

                      Thanks again,

                       

                      Jason

                      • 8. Re: Scripting
                        shearn

                        The END IF for your FoundCount test is inside the Loop. The only time the script will execute the second loop is if the IF is true. If it's false, the next step that tries to run is an END LOOP which makes no sense since there was no LOOP to open it. Just move the END IF after the END LOOP.

                         

                        I thought you wanted these steps to execute if you have records in your found set? If so, then your IF calc should be "Get (FoundCount)>0" as I had in my previous post. It doesn't make any sense to constrain your found set if you don't have any records that are found.

                        • 9. Re: Scripting
                          Jason_Farnsworth

                          I get the Error as soon as I move to the other side of the Loop Command 8 Lines Down.

                          • 10. Re: Scripting
                            LyndsayHowarth

                            you have an If statement outside the loop and the End If statement that matches it inside the Loop. This is not possible for FIleMaker to execute. It is like shutting the car door on your arm!

                             

                            - Lyndsay

                            • 11. Re: Scripting
                              Jason_Farnsworth

                              Ok,

                               

                              I think I got it now as you suggested - I moved the ENDIF to just after the loop and made it greater than and it is working like a charm.

                               

                              Thanks you so much for the help -

                               

                              Jason

                              • 12. Re: Scripting
                                shearn

                                You're welcome!

                                • 13. Re: Scripting
                                  LyndsayHowarth

                                  sorry... I double-checked this and that is not the case... sorry.

                                   

                                  It may be related to the fact that you turn the error capture on outside the loop and off inside the loop.

                                   

                                  Have you checked that the restored find above is valid?

                                   

                                  With long scripts, sometimes breaking them down to smaller subscripts helps troubleshoot your logic.