Exit Table Updates Properly?

I have encountered a strange issue with a button script that enters data into a UDT. I have been using this script in testing for about a month now and it hasn't had any issues until yesterday - even after a server restart.

The first time clicking this button everything executes just fine.

  1. Create UDT object Handle
  2. SetKey to new/existing record
  3. Enter some field changes
  4. Cancel changes to the UDT table by using .Clear()
  5. Set oUDT = Nothing
  6. oSession.DropObject nUDT

Then if the button is pressed again, I receive an error that states the Object doesn't support the method 'SetKey'

We are still on v2020 due to our cloud tax vendor no longer supporting Sage and we are in the process of working that out as well.

Main Question:

What's the proper way of canceling updates to a UDT that was in an EditState = 2 (new record)? Currently I am using:

'Simplified Button Script
'Script runs first time no issue, but running again fails [Obj doesn't support '.SetKey' method]
'Is the table still locked from first run? Did I release everything properly?

nUDT = oSession.GetObject("CM_UDTMaint_bus", "SO_UDT_CR_AUDIT")
if nUDT <> 0 Then
    Set oUDT = oSession.AsObject(nUDT)
    oUDT.SetKey(<Key>)  'EditState = 2 / New Entry
    
    'Perform some common entries, but now need to cancel the record creation
    
    oUDT.Clear()
    Set oUDT = Nothing
    oSession.DropObject nUDT
end if