Unable to drop object in event script

I have a working event script tied to S/O detail that fires on post validation of quantity ordered.  The script automatically creates a BOM Production Entry for the item entered, updates the production entry and updates the GL DTR.  The problem I'm having is that you must close sales order completely to have it release my DTR object.  Even if you accept the order and go back to the blank data entry screen you still see the B/M DTR in use.  Once you close S/O entry the B/M DTR task is released.  Below is my code related to grabbing the GL_DailyTransaction_Upd object and updating it.  I've tried setting my object variable to NOTHING, Clear(), etc and nothing seems to work.  Any ideas?

r = oSession.SetModule("B/M")
'msgbox("Set Module " & r)

r = oSession.SetDate("B/M", 20220104)
'msgbox("Set Date " & r)

r = oSession.SetProgram(oSession.LookupTask("GL_DailyTransactionUpdate_UI"))
'msgbox("Set Task " & r)

SET oGL_DTR = oSession.AsObject(oSession.GetObject("GL_DailyTransaction_upd"))
		'msgbox("DTR UPD Handle" & retVal)
	r = oGL_DTR.SetUpdateRegister(CurReg)   'UpdRegNo
		'msgbox("Register set? " & r & " ; Last Error:  " & gl.LastErrorMsg)
	r = oGL_DTR.ProcessReport("PREVIEW")
		'msgbox("Process Report " & gl.LastErrorMsg)
	r = oGL_DTR.Update()

Parents Reply
  • in reply to jepritch

    I added retVal = oSession.DropObject("GL_DailyTransaction_upd") but the DTR is still hanging in the Master Console until I close S/O completely. Definitely odd.  I've had another scripting person on my side look at it and he's perplexed too.

Children
  • in reply to sawzall

    Could it be the Preview is still an open thread somewhere?  If you don't care about Paperless, why not try Deferred?

  • in reply to Kevin M

    The previews and all other visible windows, that shouldn't be open, are closed and I have tried the other print options and encounter the same issue.  I even tried some of the other methods like UpdateCleanup() that are available in this object.

  • FormerMember
    FormerMember in reply to sawzall

    Orphan ProvideX tasks can be problematic.

  • in reply to sawzall

    I think it may be because you are changing the module/program using SetProgram().  You may need to set those back to "Sales Order".  I don't think the S/O task is listed anymore is it?  

    E

  • in reply to jepritch

    Good idea.  The Master Console is showing B/M DTR is in use so I'll try changing back to S/O and see if that helps.

  • in reply to jepritch

    Using SetProgram() to get me back to S/O does make the system show I'm back in S/O and out of the B/M DTR in the Master Console. Unfortunately the system still thinks an update is in process until I close the S/O entry window.  Below is my updated code.

    retVal = oSession.SetModule("B/M")
    'msgbox("Set Module " & retVal)
    
    retVal = oSession.SetDate("B/M", 20220104)
    'msgbox("Set Date " & retVal)
    
    'get a handle on the DTR object and update the DTR
    retVal = oSession.SetProgram(oSession.LookupTask("GL_DailyTransactionUpdate_UI"))
    SET oGL_DTR = oSession.AsObject(oSession.GetObject("GL_DailyTransaction_upd"))
    		'msgbox("DTR UPD Handle" & retVal)
    	retVal = oGL_DTR.SetUpdateRegister(sCurReg)
    		'msgbox("Register set? " & retVal & " ; Last Error:  " & oGL_DTR.LastErrorMsg)
    	retVal = oGL_DTR.ProcessReport("PREVIEW")
    		'msgbox("Process Report " & oGL_DTR.LastErrorMsg)
    	retVal = oGL_DTR.Update()
    		'msgbox("DTR Updated? " & retval & " ; Last Error: " & oGL_DTR.LastErrorMsg)
    retVal = oSession.DropObject("GL_DailyTransaction_upd")
    retVal = oSession.SetProgram(oSession.LookupTask("SO_SalesOrder_UI"))

    I'm so close I can taste it!  LOL!

  • in reply to sawzall

    Where exactly are you encountering an issue where the system still thinks an update is in process?

  • in reply to jepritch

    Sales Order Entry, with or without the order open.  If I go to run the DTR in GL I get the following message:

    Once I close Sales Order Entry I can run the DTR task without getting the message.

  • in reply to sawzall

    Maybe you could try dropping the BM Production Update?  Did you drop that one too?

  • in reply to jepritch

    I did add retVal = oSession.DropObject("BM_ProductionRegister_upd") after finished with the object but getting the following error:

    Odd because the error is referencing something in the next object that works if I don't drop the previous object:

    'get a handle on the BOM production register update object and update the register
    SET peu = oSession.AsObject(oSession.GetObject("BM_ProductionRegister_upd"))
    	retVal = peu.SelectBatch(sBatchNo)
    	retVal = peu.ProcessReport("PREVIEW")
    	retVal = peu.Update()
    retVal = oSession.DropObject("BM_ProductionRegister_upd")
    
    retVal = oSession.SetModule("B/M")
    'msgbox("Set Module " & retVal)
    
    retVal = oSession.SetDate("B/M", 20220104)
    'msgbox("Set Date " & retVal)
    
    'get a handle on the DTR object and update the DTR
    retVal = oSession.SetProgram(oSession.LookupTask("GL_DailyTransactionUpdate_UI"))
    SET oGL_DTR = oSession.AsObject(oSession.GetObject("GL_DailyTransaction_upd"))
    		'msgbox("DTR UPD Handle" & retVal)
    	retVal = oGL_DTR.SetUpdateRegister(sCurReg)
    		'msgbox("Register set? " & retVal & " ; Last Error:  " & oGL_DTR.LastErrorMsg)
    	retVal = oGL_DTR.ProcessReport("PREVIEW")
    		'msgbox("Process Report " & oGL_DTR.LastErrorMsg)
    	retVal = oGL_DTR.Update()
    		'msgbox("DTR Updated? " & retval & " ; Last Error: " & oGL_DTR.LastErrorMsg)
    retVal = oSession.DropObject("GL_DailyTransaction_upd")
    retVal = oSession.SetProgram(oSession.LookupTask("SO_SalesOrder_UI"))