Have a script that calculate a discount per a total weight on the order. New orders work correctly but when an order is modified on the modified lines are updated the other lines retain the previous discounts.
'Int Var
sItem = ""
nTWght = 0
nDisc10000 = 0
nDisc20000 = 0
nDisc42000 = 0
nUnitPrice = 0
oCItem = 0
nStdPrice = 0
nDiscount = 0
ntmpsell = 0
sScriptName =""
sCustomer =""
sScriptName = "UpdateLinesDiscount"
r=oScript.DebugPrint("Made it to " & sScriptName)
'Get Sales Order total weight and customer included in pricing tier
RV = oBusObj.GetValue("UDF_TTL_ORDER_WGT",nTWght):r= oScript.DebugPrint("2ndScript_Got Value nTWght =" & nTWght)
Set oLines=oBusObj.AsObject(oBusObj.Lines)
retval= oLines.MoveFirst()
Do While CBool(oLines.EOF) = False
retVal = oLines.GetValue("ItemCode$",sItem): r=oScript.DebugPrint("Got Value from sItem = " & sItem)
retVal = oLines.GetValue("UnitPrice",nUnitPrice): r=oScript.DebugPrint("Got Value from nUnitPrice = " & nUnitPrice)
retval = oLines.GetValue("UDF_StandardUnitprice",nStdPrice):r= oScript.DebugPrint("Got Value nStdPrice=" & nStdPrice)
retVal = oLines.GetValue("UDF_10000_DISC", nDisc10000):r= oScript.DebugPrint("Got Value nDisc10000 =" & nDisc10000)
retVal = oLines.GetValue("UDF_20000_DISC", nDisc20000):r= oScript.DebugPrint("Got Value nDisc20000 =" & nDisc20000)
retVal = oLines.GetValue("UDF_42000_DISC", nDisc42000):r= oScript.DebugPrint("Got Value nDisc42000 =" & nDisc42000)
retVal = olines.GetValue("UDF_DISCOUNT_AMT",nDiscount):r= oScript.DebugPrint("Got Value nDiscount =" & nDiscount)
'Stop the script if the Unit price and Std price are not the same.
if nUnitPrice = nStdPrice then
'Determine which tier of discount needs to be used based on the total weight of the order.
if nTWght > 10000 and nTWght < 20000 then nDiscount = nDisc10000
rWrite = oLines.Write ()
if nTWght > 20000 and nTWght < 42000 then nDiscount = nDisc20000
rWrite = oLines.Write ()
if nTWght > 42000 then nDiscount = nDisc42000
rWrite = olines.write ()
retVal = oLines.SetValue("UDF_DISCOUNT_AMT",nDiscount)
r=oScript.DebugPrint("Final Discount =" & nDiscount)
retVal = oLines.GetValue("UDF_NEW_UNIT_PRICE",nNewUnitPrice):r= oScript.DebugPrint("Got Value nNewUnitPrice=" & nNewUnitPrice)
nNewUnitPrice = nUnitPrice-nDiscount :r = oScript.DebugPrint("New Unit Price is nNewUnitPrice =" & nNewUnitPrice)
nUnitPrice = nNewUnitPrice
rv = oLines.SetValue ("UnitPrice",nUnitPrice):r = oScript.DebugPrint("Current Unit Price nUnitPrice=" & nUnitPrice)
rWrite = oLines.Write
End If
retVal = oLines.MoveNext()
Loop
------------------------------
Venessa Griffin
RKL eSolutions, LLC
------------------------------