Skip to Content
0
Former Member
Oct 18, 2006 at 02:20 PM

Closing a draft

22 Views

I am trying to close an exisitng draft via DI API - SAP B1 2005 A SP 00 PL 11.

I don't receive an error but the draft is open too.

Why?

'----


Private Function ChiusuraBozza(ByVal lDocEntry As Long) As Boolean

Try

Dim oDraft As SAPbobsCOM.Documents

oDraft = m_oCmp.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDrafts)

'Check errors

Dim bRetVal As Boolean

bRetVal = oDraft.GetByKey(lDocEntry)

Dim lErrCode As Long

Dim sErrMsg As String

If (Not bRetVal) = True Then

m_oCmp.GetLastError(lErrCode, sErrMsg)

If lErrCode <> 0 Then Throw New Exception(sErrMsg)

End If

If oDraft.DocNum = 0 Then

sErrMsg = "Bozza n." & lDocEntry

Throw New Exception(sErrMsg & " non trovata con il GetByKey")

End If

If oDraft.DocumentStatus = SAPbobsCOM.BoStatus.bost_Open Then

'Chiusura bozza

bRetVal = oDraft.Close

If (Not bRetVal) = True Then

m_oCmp.GetLastError(lErrCode, sErrMsg)

If lErrCode <> 0 Then

Throw New Exception("Bozza n." & oDraft.DocNum & " aperta: " & sErrMsg)

End If

End If

If Not SBOLog Is Nothing Then SBOLog.WriteLog(Me.ToString(), "ChiusuraBozza()", "Bozza n." & oDraft.DocNum & " chiusa correttamente", C_Log.TIME_MEDIUM, C_Log.Levels.LEVEL_GOOD)

End If

oDraft = Nothing

ChiusuraBozza = True

Catch ex As Exception

If Not SBOLog Is Nothing Then SBOLog.WriteLog(Me.ToString(), "ChiusuraBozza()", ex.Message, C_Log.TIME_MEDIUM, C_Log.Levels.LEVEL_ERROR)

ChiusuraBozza = False

End Try

System.GC.Collect() 'Release the handle to the table

End Function