Sage 100

 View Only
  • 1.  Line not updating with script on modified order

    Posted 08-22-2020 18:40
    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
    ------------------------------


  • 2.  RE: Line not updating with script on modified order

    Posted 08-23-2020 01:45
    It is probably because you are both checking that the line unit price equals the standard unit price and you are setting the line unit price to a different value if they were the same at one point, in doing so, it causes the line unit price to no longer equal the standard unit price when checked in future executions of the script.

    You can always add debug print lines at the top of your If and Else sections so you can identify which portions of you script is being stepped into.

    ------------------------------
    David Speck II
    Tennessee Software Solutions
    ------------------------------



  • 3.  RE: Line not updating with script on modified order

    Posted 08-24-2020 12:29
    Whenever I do a calculation to change UnitPrice based on a script formula I capture the original unit price in a UDF, and use that for all calculations.  That way I never apply a discount on a discount on a discount... so if you are using the StandardCost the same way, don't skip processing when the UnitCost does not equal Standard.  Just always apply the discount to Standard.  Of course, this skips all customer pricing, which is why I use a UDF.

    ------------------------------
    Kevin Moyes
    Technical Systems Analyst
    Munjal White Consulting Co.
    Toronto ON
    ------------------------------