cancel
Showing results for 
Search instead for 
Did you mean: 

Credit memo draft adding 7 times automatically

Former Member
0 Kudos

Dear all,

I created draft for credit memo. i converted this draft to credit memo by using DI API. but its adding 7 times automattically (vocationaly).

With regards

Venkatesan .A

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Dear

To work around this, you can get the draft, save it as

XML, change the nodenames to adjust them to the new object, delete the

Key for header and lines and get it from XML to save it in the DB. We

have samples at the bottom of Document Object in SDK online help. I

paste the code below, it's about "save a draft document to xml and then

creates a new order based on the xml"

Example

Private Sub cmdDraftToOrder_Click()

Dim pDraft As SAPbobsCOM.Documents

Set pDraft = vCmp.GetBusinessObject(oDrafts)

Dim pOrder As SAPbobsCOM.Documents

vCmp.XmlExportType = xet_ExportImportMode

vCmp.XMLAsString = False

pDraft.GetByKey (3)

pDraft.SaveXML ("c:\drafts.xml")

'Here you should add a code that will change the Object's

'value from 112 (Drafts) to 17 (Orders) and also you should

'remove the DocObjectCode node from the xml. You can use any

'xml parser.

'

'Create a new order

Set pOrder = vCmp.GetBusinessObjectFromXML("c:\drafts.xml", 0)

pOrder.Add

End Sub

Acturally, there is not such method in current DI API that will convert

draft to document straightaway. you may refer to above code for your credit memo to see if it works for you

Hope the above information helps.

best regards,

xiaodan an

Former Member
0 Kudos

thanks for your reply.

But i did the same. i written coding format below, but it adding credit memo seven times occasionally.

event:

-


If BusinessObjectInfo.EventType = BoEventTypes.et_FORM_DATA_ADD And (BusinessObjectInfo.FormTypeEx = "133" Or BusinessObjectInfo.FormTypeEx = "60090") And BusinessObjectInfo.BeforeAction = True And BusinessObjectInfo.ActionSuccess = False Then

Dim objForm As SAPbouiCOM.Form

objForm = objSBO_Application_ARINV.Forms.ActiveForm

objCompany_ARINV.StartTransaction()

Dim chkStatus As Boolean

chkStatus = OtherUpdations(objForm)

If chkStatus = True Then

Dim RsMax As Recordset

Dim Query As String

objCompany_ARINV.EndTransaction(BoWfTransOpt.wf_Commit)

BubbleEvent = True

Else

Try

objCompany_ARINV.EndTransaction(BoWfTransOpt.wf_RollBack)

Catch ex As Exception

objSBO_Application_ARINV.MessageBox(ex.ToString)

End Try

BubbleEvent = False

Exit Sub

End If

End If

OtherUpdations

-


Function OtherUpdations(ByVal objForm As Form) As Boolean

DraftNosSplit = Split(DraftNos, ",")

For i = 0 To DraftNosSplit.Length - 1

DraftNo = DraftNosSplit(i)

Query = " select * from odrf where docentry='" & DraftNo & "'"

RsInfo = objCompany_ARINV.GetBusinessObject(BoObjectTypes.BoRecordset)

RsInfo.DoQuery(Query)

If RsInfo.EoF = False Then

FileName = "CM" & Date.Now.Ticks.ToString() & ".xml"

DocumentPath = System.AppDomain.CurrentDomain.BaseDirectory() & "MLSBLImport\" & FileName

objDraft = objCompany_ARINV.GetBusinessObject(BoObjectTypes.oDrafts)

objCompany_ARINV.XmlExportType = BoXmlExportTypes.xet_ExportImportMode

objCompany_ARINV.XMLAsString = False

Search = objDraft.GetByKey(DraftNo)

If Search = False Then

objCompany_ARINV.GetLastError(ErrCode, Errmsg)

MsgBox("Failed to Retrieve the record " & ErrCode & " " & Errmsg)

Return False

Exit Function

End If

objDraft.SaveXML(DocumentPath)

'Here you should add a code that will change the Object's

'value from 112 (Drafts) to 17 (Orders) and also you should

'remove the DocObjectCode node from the xml.

Dim m_xmld As XmlDocument

Dim m_nodelist As XmlNodeList

Dim m_node As XmlNode

Dim m_childNode As XmlNode

'Dim m_node As XmlNode

'Create the XML Document

m_xmld = New XmlDocument

'Load the Xml file

m_xmld.Load(DocumentPath)

'Get the list of name nodes

' m_nodelist = m_xmld.SelectNodes("/BOM/BO")

m_node = m_xmld.SelectSingleNode("/BOM/BO/AdmInfo/Object")

If Not m_node Is Nothing Then

m_node.InnerText = "14"

End If

m_node = Nothing

m_node = m_xmld.SelectSingleNode("/BOM/BO/Documents/row")

m_childNode = m_xmld.SelectSingleNode("/BOM/BO/Documents/row/DocObjectCode")

If Not m_node Is Nothing Then

m_node.RemoveChild(m_childNode)

End If

m_childNode = m_xmld.SelectSingleNode("/BOM/BO/Documents/row/CardCode")

If Not m_node Is Nothing Then

m_childNode.InnerText = sCardCode

End If

m_childNode = Nothing

m_childNode = m_xmld.SelectSingleNode("/BOM/BO/Documents/row/CardName")

If Not m_node Is Nothing Then

m_childNode.InnerText = sCardName

End If

m_childNode = Nothing

m_childNode = m_xmld.SelectSingleNode("/BOM/BO/Documents/row/Address")

If Not m_node Is Nothing Then

m_childNode.InnerText = sAddress

End If

m_childNode = Nothing

m_childNode = m_xmld.SelectSingleNode("/BOM/BO/Documents/row/Address2")

If Not m_node Is Nothing Then

m_childNode.InnerText = sAddress2

End If

m_childNode = Nothing

m_childNode = m_xmld.SelectSingleNode("/BOM/BO/Documents/row/ShipToCode")

If Not m_node Is Nothing Then

m_childNode.InnerText = sShipToCode

End If

m_childNode = Nothing

m_childNode = m_xmld.SelectSingleNode("/BOM/BO/Documents/row/PayToCode")

If Not m_node Is Nothing Then

m_childNode.InnerText = sBillToCode

End If

m_childNode = Nothing

m_node = Nothing

m_xmld.Save(DocumentPath)

objCM = objCompany_ARINV.GetBusinessObjectFromXML(DocumentPath, 0)

'Create a new Credit Memo

RetVal = objCM.Add()

If RetVal <> 0 Then

objCompany_ARINV.GetLastError(ErrCode, Errmsg)

MsgBox("Failed to Retrieve the record " & ErrCode & " " & Errmsg)

Return False

Exit Function

Else

'RsMax = objCompany_ARINV.GetBusinessObject(BoObjectTypes.BoRecordset)

'Query = "Select max(docentry) DocEntry from ORIN"

'RsMax.DoQuery(Query)

RsMax = objCompany_ARINV.GetBusinessObject(BoObjectTypes.BoRecordset)

Query = "Select max(docentry) DocEntry from ORIN"

RsMax.DoQuery(Query)

If RsMax.EoF = False Then

DocEntry = RsMax.Fields.Item("DocEntry").Value

BeatenDocEntryNos = BeatenDocEntryNos & DocEntry & ","

End If

End If

If File.Exists(DocumentPath) = True Then

File.Delete(DocumentPath)

End If

'lRetCode = objDraft.Remove()

'If lRetCode <> 0 Then

' objCompany_ARINV.GetLastError(lRetCode, sErrMsg)

' objSBO_Application_ARINV.MessageBox(sErrMsg & " Error in Delete Draft")

' Return False

' Exit Function

'End If

End If

Next

end function

Edited by: Rui Pereira on Dec 23, 2008 3:00 PM

Answers (0)