Unable to get previous Sales Order Lines on table - Pre Write?

Hello, 

I'm simply wanting to write the previous item code to a UDT when the line is changed in a sales order. For example, if the item code was abc123 and a user changed it to def456, I want to write abc123 to the UDT. However, each time I try to access the line in the history file, the script always writes the new item code (def456) to the udt and not the old one. It seems as  if the new item is being written to the sales order history file before the record is written, even though my script is table pre-write.

Is there a way to do this? Why is the new value already stored in the history file even though this script accesses it before I write the new value? I have tried accessing the "Previous" lines through all of the history business objects with the same result. I have been stuck on this for quite some time and would greatly appreciate some help!

itemC = ""
soNumb = ""

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

set oLog = oSession.AsObject(oSession.GetObject("CM_UDTMaint_bus", "SO_UDT_SO_CHANGE_TRACK"))
Set oHist = oSession.AsObject(oSession.GetObject("SO_SalesOrderHistoryInquiryDetail_bus"))

retVal = oHist.SetKeyValue("SalesOrderNo$", soNumb)
retVal = oHist.setKeyValue("SequenceNo$", 1)
oHist.Find()
retVal = oHist.GetValue("ItemCode$", itemC)
oLog.SetKey(itemC)
oLog.Write()

Edit: This script is tied to the sales order header

  • 0

    I AM able to get the header information when changed using this method, just not the detail information. 

  • 0 in reply to Surya IT

    Upon further review, it looks like the sales order and quote history field is updated as soon as an item code is changed, NOT when I hit accept. Is there a way to pass variables between scripts? I'm assuming I would have to do a post-read on the SO file before changes, and then pass this to my current script but not sure how.

  • 0 in reply to Surya IT

    Look at SetStorageVar and GetStorageVar.

  • 0 in reply to Kevin M

    Thanks Kevin, This seems to work for a single variable, but if I try to pass through multiple variables I get the error: Invalid/Missing variable on the GetStorageVar Method. 

    Here is my SET code: (Post Read on Header)

    Set oLines = oBusobj.AsObject(oBusObj.Lines)
    oLines.MoveFirst()
    do Until cBool(oLines.EOF)
         retVal = oLines.GetValue("ItemCode$", itemC)
         aItem(n) = itemC
         retVal = oSessionScript.SetStorageVar(CStr(mStr), aItem(n))
         mStr = mStr & "a"
        retVal = oLines.MoveNext()

    Loop

    Here is my GET code: (Pre-Write on Header)

     

    g = "a"

    set oLines = oBusObj.AsObject(oBusObj.Lines)
    oLines.MoveFirst()
    do Until cBool(oLines.EOF)
         retVal = oSessionScript.GetStorageVar(g, a)
         retVal = oLines.GetValue("ItemCode$", itemCD)
         if itemCD <> a then
              retVal = oLog.SetKey(itemCD & a)
              oLog.Write()
         end if
         g = g & "a"
    Loop

  • 0 in reply to Surya IT

    For got an oLines.MoveNext on my GET(). Working now...