4 Replies Latest reply on Jan 13, 2017 7:06 AM by philmodjunk

    Exit loop when after x times.

    muhammad.ikram@contedia.com

      Hello

       

      I have an order form which has an "Quantity" field; allowing user to add an quantity number.

       

      What I want is when user enter quantity more than one; FileMaker to save the same record same number as entered quantity.

       

      So if user enter 2 Quantity, I want to have 2 separate records added to my database table containing same order information, just different ID.

       

      I got this script, but it neither show any errors and neither work.

       

       

      Thank you in Advance.

        • 1. Re: Exit loop when after x times.
          philmodjunk

          The main missing detail is that the loop in your script never modifies the $QuantityOrdered variable

           

          You need this step located between the Loop and End Loop steps:

           

          Set Variable [$QuantityOrdered ; value $QuantityOrdered - 1 ]

           

          To reduce the count in this variable by 1 each time the loop is executed.

           

          Your Exit Loop step should exit the loop when this variable reaches 0

           

          Exit Loop If [ $QuantityOrdered < 1 ]

           

          And I don't know the purpose of $$ButtonSave, but you do not need to set it to 1 over and over within the loop.

          • 2. Re: Exit loop when after x times.
            wkeja

            You start allright: set a variable that represents the number of orders.

            Then you start a loop, with the condition Exit Loop If x = x. This condition is met immediately, so the loop will never take place. You should use the variable as a counter:

             

            Loop

            Exit Loop If $quantityOrdered = 0

            >

            >

            >

            Set Variable [$quantityOrdered; $quantityOrdered -  1]

            End Loop

             

            Hope this helps.

            • 3. Re: Exit loop when after x times.
              muhammad.ikram@contedia.com

              Thank you for fast response.

               

              I have amended the script.

               

               

              When enter the quantity and click save, the curse change to waiting sign and seems like loop don't exit.

              It saves the record once, but doesn't save the records according to the quantity entered.

              • 4. Re: Exit loop when after x times.
                philmodjunk

                We were focused on getting the loop to work.

                 

                You also need steps for creating a new record. How you do that depends on the context in which this script executes.

                 

                If your script is executing on a layout based CustomerOrders, you need a new/Record script step. If CustomerOrders represents a record from a related table, you'll need to do a bit more scripting--either to change to a layout based on CustomerOrders, interact with a portal (This works, but I recommend against this option), or via a method known as MagicKey.