2 Replies Latest reply on Nov 16, 2012 3:26 PM by Kirk_1

    Loop in a Loop

    Kirk_1

      Title

      Loop in a Loop

      Post

           Im doing a loop in a loop...

           The 1st loop takes the found set and performs a series of set fields.

           The loop in the loop sets a field in a portal. if the next line in the portal is empty i want it to go to finish the rest of the outer loop...

            

             
      •           Loop
      •      
      •           Go to Object [ Object Name: "InvoiceLI" ]
      •      
      •           Go to Portal Row [ Select; First ]
      •      
      •           Loop
      •      
      •           Set Field [ InvoiceLineItem::LIPosted; "x" ]
      •      
      •           Go to Portal Row [ Select; Next; Exit after last ]
      •      
      •           If [ InvoiceLineItem::LIAmount = "" ]
      •      
      •           End If
      •      
      •           End Loop

            

           This script just goes through the entier portal. it won't let me move the end loop up before the end if... How do i do this?

        • 1. Re: Loop in a Loop
          philmodjunk

               I suspect that "allow creation of records" is enabled for the portal.

               That gives you one more portal row than you have portal records, the blank "add" row where you enter data to create a new portal record.

               Thus, your loop keeps adding a new record in the "add" row and never gets to the last portal row.

               If you step through this script in the script debugger (Filemaker Advanced) or put a pause script step right after the set field, you'll see what I am describing. (I've made this mistake myself.)

               You could use a counting variable that increments with each loop and an exit loop If stept that compares the variable to the number of related records, but your script would be simpler if you froze the window, used Go to Related Records to pull up the found set of line items on a layout base on line items and then used Replace Field Contents to set the "x" in the Posted field.

          • 2. Re: Loop in a Loop
            Kirk_1

                 Ill do the related records, i already have a layout.

                 Thank you