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
  • +1
    verified answer

    It looks like this script is attached to the Post-Write of the SO_SalesOrderDetail business object.   It's important to know that the data entry model, writes the line detail to an internal memory file and is committed to the physical table when the entire sales order is written.  The script on the post-write of the detail object allows us to act on each line as it's written to the temporary table.

    You should also have a Post-Delete script that mirrors the Post-Delete in that it backs out the quantities, this way if a line is deleted it reduces the salespersons totals as well.  If you have both scripts, I believe you will have the desired effect.

    If the order is cancelled it should run the Post-Delete script of each line to reverse your changes.

    Hope this helps, Elliott

Reply
  • +1
    verified answer

    It looks like this script is attached to the Post-Write of the SO_SalesOrderDetail business object.   It's important to know that the data entry model, writes the line detail to an internal memory file and is committed to the physical table when the entire sales order is written.  The script on the post-write of the detail object allows us to act on each line as it's written to the temporary table.

    You should also have a Post-Delete script that mirrors the Post-Delete in that it backs out the quantities, this way if a line is deleted it reduces the salespersons totals as well.  If you have both scripts, I believe you will have the desired effect.

    If the order is cancelled it should run the Post-Delete script of each line to reverse your changes.

    Hope this helps, Elliott

Children