AnsweredAssumed Answered

Applying/calculating correct values during loop

Question asked by AdamHorne on May 9, 2016
Latest reply on May 9, 2016 by 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?

Outcomes