Multiple table writes requires multiple Objects? (Audit Script)

Hello, 

I am in the process of building a "Change Tracking" system for Sales orders which tracks any changes to a specified list of fields. To do this, on a Table Pre-Write script I simply gather the information from the So History record and compare it to the SO (live) record, and if fields do not match up I log the change in a UDT. Here are my issues:

Problem 1 is that in order to track the "Order Status" field, I have had to write an initial "Created" line to my UDT for ALL sales orders so that I have a reference point against which I can compare this field, as the "Order Status" is different in the history file. This way, I can update one field as the most recent order status, and update this if/when it changes. I would rather not have to create a record for all newly created sales orders though, only those which have been altered...

Problem 2 is that I have not been able to do multiple table writes with the same Object handle. Is this as intended, or is there some sort of drop/reset that I am missing? I have tried using the same handle but setting a new key, and a variety of other methods but the only thing that seems to work is creating a separate one in order to do a separate write. The section of the script for this problem is posted below. 

Any guidance in either of these issues would be greatly appreciated!

..........

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

if ShipToAddress1New <> ShipToAddress1Current then
resul = oLog.setKey(SoNumb & "sa1")
retVal = oLog.setValue("UDF_FIELD_CHANGED$", "ShipToAddress1")
retVal = oLog.setValue("UDF_PREVIOUS_VALUE$", ShipToAddress1Current)
retVal = oLog.setValue("UDF_NEW_VALUE$", ShipToAddress1New)
retVal = oLog.setValue("UDF_TIME_CHANGED$", sTime)
retVal = oLog.setValue("UDF_DATE_CHANGED$", sDate)
retVal = oLog.setValue("UDF_ORDER_NUMBER$", SoNumb)
retVal = oLog.setValue("UDF_CURRENT_STATUS$", StatusCurrent & " " & StatusNew)
retVal = oLog.setValue("UDF_USER_MODIFIED$", sUser)
oLog.Write()

End If

if ShipToAddress2New <> ShipToAddress2Current then
set oCheck = oSession.AsObject(oSession.GetObject("CM_UDTMaint_bus", "SO_UDT_SO_CHANGE_TRACK"))
resul = oCheck.SetKey(soNumb & "sa2")
retVal = oCheck.setValue("UDF_FIELD_CHANGED$", "ShipToAddress2")
oCheck.Write()
End If

Parents Reply Children
  • 0 in reply to connex

    For my Issue number 1, I thought of a few ways to do this but at the end of the day I think I'm just going to do it the way I initially stated. I will just have to create another script that deletes records which have had no changes and are order status 'Complete'

    For issue number 2, I'm not sure why my first attempts did not work using the same handle, but I was able to change the "set Ocheck = ..." line to "oLog.setKey("sa2" &soNumb)." Not sure if I had some silly syntax error the first time, or if it matters that my string comes before my variable when setting the key, but this works fine.