2 Replies Latest reply on May 9, 2016 9:23 AM by AdamHorne

    Applying/calculating correct values during loop

    AdamHorne

      Note: This is only for PRINT purposes, I'm handing the inventory side of it differently. Also this is rental equipment, not sales so items are returned.

       

       

      Lets say, I have (2) Parent Items, each with (1) Accessory/Child Item on an order.

       

       

      ORDER# 1234

      (3) Apple TV (ID = 001)

        - (3) HDMI Cable (ID = 003)

      (2) 21" Samsung Monitors (ID = 002)

        - (2) HDMI Cable (ID = 003)

       

       

      I have all (3) Apple TV's returned, but only (1) Samsung Monitor. I have a button, which brings a popup and I enter the amount of HDMI cables returned.  In this example, (4) cables were returned.

       

       

      My current setup, will go to the orderlines and search for the orderID and the equipmentID.  So it searches and finds (2) records. 

       

       

      I would like for it to apply (3) cables to the Apple TV and see that only (3) were needed and move to the next line item and continue. However, its applying (4) to the first record. Everytime I return an HDMI on this order, its applied to the first line item.

       

       

      I'm working on a script, but having trouble figuring out the correct formula/steps.

       

       

      ************************BEGIN SCRIPT ***************************************************

      # Set var for testing purposes. Will take value from Custom Dialog...

      # Global $$ will be replaced with local $

       

       

      Set Variable [ $$returnCount ; Value: 4 ]

       

       

      Set Variable [ $i ; Value: $i + 1 ]

       

      If [ Get(FoundCount) ≥ 2 ]

      Loop

       

        Exit Loop If [ $$returnCount = 0  or $i > Get(FoundCount) ]

        Go to Record/Request/Page [ No dialog ; $i ]

       

        # Set Var for QtyOut

        Set Variable [ $qtyOut ; Value: ORDERLINEITEMS::qtyOut ]

       

        # Set Var for remainingQty

        Set Variable [ $$remainingQty ; Value: If (   $qtyOut ≥ $$returnCount ; $qtyOut - $$returnCount ;   Abs ( $qtyOut - $$returnCount )    ) ]

       

        Set Variable [ $i ; Value: $i + 1 ]

        Set Variable [ $$returnCount ; Value: $$remainingQty ]

       

           End Loop

      End If

       

      # Clean up variables

      Set Variable [ $$returnCount ]

      Set Variable [ $$remainingQty ]

       

       

      ************************END SCRIPT******************************************************

       

       

      My problem is with my formula for $$remainingQty.

       

       

      When I step through the script the first time, it works.  During the second loop is where my values get screwed up.

       

       

      First Pass:

        $returnCount = 4

        $QtyOut = 3

        $remainingQty = 1

       

       

      Second Pass:

        $returnCount = 1

        $QtyOut = 2

        $remainginCount = 1

       

       

      How do I get $remainingCount to zero out?  I've thought about setting a exitLoop var:

       

       

      $exitLoop = Case ( $$returnCount - $$remainingQty = 0 ; "true" ; "false" )

       

       

      However, it exits the loop too early, leaving (1) item needing to be applied.

       

       

      Any thoughts or suggestions?

        • 1. Re: Applying/calculating correct values during loop
          erolst

          See my comments in the quoted script, and a suggestion for simplification.

          AdamHorne wrote:

           

          Set Variable [ $$returnCount ; Value: 4 ]

          Set Variable [ $i ; Value: $i + 1 ]

          Loop

            If [ Get(FoundCount) ≥ 2 ]

             # you're doing nothing to change the found set, so why not test this once – outside the loop?

              Exit Loop If [ $$returnCount = 0 or $i > Get(FoundCount) ]

              Go to Record/Request/Page [ No dialog ; $i ]

              # Set Var for QtyOut

              Set Variable [ $qtyOut ; Value: ORDERLINEITEMS::qtyOut ]

              # Set Var for remainingQty

              # if returned > qty, isn't there something askew?

              Set Variable [ $$remainingQty ; Value: If ( $qtyOut ≥ $$returnCount ; $qtyOut - $$returnCount ;

              Abs (   $qtyOut - $$returnCount ) ) ]

              # simplify to Abs ( $qtyOut - $$returnCount ) ?

              Set Variable [ $i ; Value: $i + 1 ]

              Set Variable [ $$returnCount ; Value: $$remainingQty ]

            End If

          End Loop

          # Clean up variables

          Set Variable [ $$returnCount ]

          Set Variable [ $$remainingQty ]

           

          Set Variable [ $$returnCount ; Value: 4 ]

          Go to Record [ First ]

          Loop

            Set Variable [ $out ; ORDERLINEITEMS::qtyOut ]

            Set Variable [ $apply ; Min ( Min ( $out ; $$returnCount ) ; $out ) ]

            Set Field [ ORDERLINEITEMS::returned ; $out - $apply ]

            Set Variable [ $$returnCount ; $$returnCount - $apply ]

            Exit Loop if [ not $$returnCount or Get ( RecordNumber ) = Get ( FoundCount ) ]

            Go to Record [ next ]

          End Loop

          Set Variable [ $$returnCount ]

          • 2. Re: Applying/calculating correct values during loop
            AdamHorne

            Thanks for the help, erolst. Your suggestions make sense.

             

            This worked great!