Post-Write Script is firing before the record is written.

SOLVED

Hello, 

I am trying to write a simple tracking script that records the number of items within a specific product line a salesperson has purchased. I currently have this script as "Table: Post-Write", but even if I cancel my order in Sales Order Entry, the quantity ordered is added to my tracking UDT. 

What do I need to do to my script to ensure that it does not fire unless the sales order is placed? 


'-----------------------

'Initialize Variables
SP = ""
ItemC = ""
pLine = ""
Qty = 0
QtyOld = 0
cap = 0

price = 0

'--------------------------

'Grab Data
retVal = oHeaderObj.GetValue("SalesPersonNo$", SP)
retVal = oBusObj.GetValue("ItemCode$", ItemC)
retVal = oBusObj.GetValue("QuantityOrdered", Qty)
retVal = oBusObj.GetValue("UnitPrice", price)

set oCap = oSession.AsObject(oSession.GetObject("CM_UDTMaint_bus", "AR_UDT_SALESPERSON_CAP"))
set oItem = oSession.AsObject(oSession.GetObject("CI_ItemCode_bus"))
retVal = oItem.GetValue("ProductLine$", pLine)
'-----------------------------

'Set Values

resul = oCap.SetKey(SP + pLine)

If resul = 2 Then
result = oCap.SetValue("UDF_Current_Qty", Qty)
result = oCap.Write()
End If

If resul = 1 Then
result = oCap.GetValue("UDF_Current_qty", QtyOld)
result = oCap.SetValue("UDF_Current_qty", QtyOld + Qty)
result = oCap.Write()
End If

'--------------------------------

Top Replies

Parents Reply
  • 0 in reply to Surya IT

    You will have to retrieve the object handle via the oLines object, something like:

    Set oLines = oSession.AsObject(oBusObj.Lines)

    Set oItem = oSession.AsObject(oLines.GetChildHandle("ITEMCODE"))

    I'm not sure your logic above would have worked as it is in your example.

    But once you have the oItem above you should be able to use it for your GetValue() of the ProductLine.

    Thanks

    Elliott

Children