Link PO Detail to SO Detail

SOLVED

Trying to update the SO Detail line after a receipt of goods is updated for a PO.  I have this script set in PO Detail on a table-postwrite but the first time I ran it the SO udf did not update.  Does the PO Detail table get updated after a receipt of goods update (I assumed it would)?  Or is something off in this script (I used an outline from an old post trying to update the other way around SO to PO).

Dim sItemCodeCur
Dim sPO_QTYREC
Dim sSO_QTYREC
Dim sOrderStatus

sSalesOrderNo = ""
sItemCode = ""
sItemCodeCur = ""
sPO_QTYREC = ""
sSO_QTYREC = ""
sOrderStatus = ""

retVal = oBusObj.GetValue("SalesOrderNo$",sSalesOrderNo)

if sSalesOrderNo <> "" then

            retVal = oBusObj.GetValue("ItemCode$",sItemCode)

            retVal = oBusObj.GetValue("UDF_QTY_RECEIVED$",sPO_QTYREC)

            if sPO_QTYREC <> "" then

                        sSO_QTYREC = sPO_QTYREC

                        oSalesOrder = oSession.GetObject("SO_SalesOrder_bus")

                        if oSalesOrder <> 0 then

                                    Set oSalesOrder = oSession.AsObject(oSalesOrder)

                        end if

                        retVal = oSalesOrder.SetKeyValue("SalesOrderNo$", sSalesOrderNo)

                        retVal = oSalesOrder.SetKey()

                        if retVal = 1 then

                                    retVal = oSalesOrder.GetValue("OrderStatus$",sOrderStatus)

                                    Set oSOLine = oSession.AsObject(oSalesOrder.Lines)

                                    retVal = oSOLine.MoveFirst()

                                    do until oSOLine.Eof

                                                retVal = oSOLine.GetValue("ItemCode$",sItemCodeCur)

                                                if sItemCode = sItemCodeCur AND sOrderStatus = "N" then

                                                            retVal = oSOLine.SetValue("UDF_QTYREC",sSO_QTYREC)

                                                            retVal = oSOLine.Write()

                                                            retVal = oSalesOrder.Write()

                                                end if

                                     retVal = oSOLine.MoveNext()

                                    loop

                        end if

                        retVal = oSession.DropObject("SO_PurchaseOrder_bus")

            end if

end if