on 07-26-2005 7:01 AM
Hi,
We are trying to create a Deliery note for a SO using DI API. We are using SAP 2004A and creating the Addon using VB.NET
If the SO has a single line then the deliver note gets created properly. When the SO has multiple line items then the following error occurs "target item code mismatch base itemcode [odln.doctype]".
Can some one help me on this.
Thanks in Advance Ganesh.
This is the code that i use to create the Delivery note
vSO = pCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders)
If vSO.GetByKey(sSO) Then
vDelivery = pCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDeliveryNotes)
vDelivery.CardCode = vSO.CardCode
vDelivery.SalesPersonCode = vSO.SalesPersonCode
vDelivery.DocType = SAPbobsCOM.BoDocumentTypes.dDocument_Items
vDelivery.DocumentSubType = SAPbobsCOM.BoDocumentSubType.bod_None
vDelivery.Address = vSO.Address
vDelivery.ShipToCode = vSO.ShipToCode
vDelivery.Address2 = vSO.Address2
vDelivery.HandWritten = SAPbobsCOM.BoYesNoEnum.tNO
vDelivery.JournalMemo = "Delivery - " &vSO.CardCode
vDelivery.Comments = "Based on SO " & sSO
vDelivery.PaymentGroupCode = vSO.PaymentGroupCode
vSOLines = vSO.Lines
vDeliveryLines = vDelivery.Lines
Dim iCnt As Integer
For iCnt = 0 To vSOLines.Count - 1
vSOLines.SetCurrentLine(iCnt)
vDeliveryLines.ItemCode = vSOLines.ItemCode
vDeliveryLines.Quantity = vSOLines.Quantity
vDeliveryLines.Rate = vSOLines.Rate
vDeliveryLines.BaseType = SAPbobsCOM.BoAPARDocumentTypes.bodt_Order
vDeliveryLines.BaseEntry = sSO
vDeliveryLines.Add()
Next
lRetCode = vDelivery.Add()
If lRetCode <> 0 Then
Dim sErr As String
pCompany.GetLastError(lRetCode, sErr)
SBO_Application.MessageBox(sErr)
End If
End If
It's actually much easier than the code you wrote.
Have a look at :
C:\Program Files\SAP Manage\SAP Business One SDK\Samples\COM DI\VB.NET\05.OrderAndInvoice
You will only create the delivery instead of the invoice (change the base ref). The "Base" values are the keys....
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I tried that sample out ... but it is not solving my purpose ...
I also found that I have missed the line num in the Delivery lines and so added that also. The error that I mentioned previously is not coming up now. But I am getting the following error ... item no. is missing [ODLN.ObjType]
and now my code looks like this ...
vSO = pCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders)
If vSO.GetByKey(sSO) Then
vDelivery = pCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDeliveryNotes)
vDelivery.CardCode = vSO.CardCode
vDelivery.SalesPersonCode = vSO.SalesPersonCode
vDelivery.DocType = SAPbobsCOM.BoDocumentTypes.dDocument_Items
vDelivery.DocumentSubType = SAPbobsCOM.BoDocumentSubType.bod_None
vDelivery.Address = vSO.Address
vDelivery.ShipToCode = vSO.ShipToCode
vDelivery.Address2 = vSO.Address2
vDelivery.HandWritten = SAPbobsCOM.BoYesNoEnum.tNO
vDelivery.JournalMemo = "Delivery - " & vSO.CardCode
vDelivery.Comments = "Based on SO " & sSO
vDelivery.PaymentGroupCode = vSO.PaymentGroupCode
<b>vDelivery.DocObjectCode = SAPbobsCOM.BoObjectTypes.oDeliveryNotes
vDelivery.DocObjectCodeEx = SAPbobsCOM.BoObjectTypes.oDeliveryNotes</b>
vDelivery.DocDueDate = Now.Month & "/" & Now.Day & "/" & Now.Year
vSOLines = vSO.Lines
vDeliveryLines = vDelivery.Lines
bLineAdded = False
Dim iCnt As Integer
For iCnt = 0 To vSOLines.Count - 1
vSOLines.SetCurrentLine(iCnt)
vDeliveryLines.ItemCode = vSOLines.ItemCode
vDeliveryLines.Quantity = vSOLines.Quantity
vDeliveryLines.Rate = vSOLines.Rate
vDeliveryLines.BaseType = SAPbobsCOM.BoAPARDocumentTypes.bodt_Order
vDeliveryLines.BaseEntry = sSO
<b>vDeliveryLines.BaseLine = iCnt</b>
<b>If bLineAdded = True Then
vDeliveryLines.Add()
End If
bLineAdded = True</b> Next
lRetCode = vDelivery.Add()
If lRetCode <> 0 Then
Dim sErr As String
pCompany.GetLastError(lRetCode, sErr)
SBO_Application.MessageBox(sErr)
End If
Note the one in Bold is the changed lines.
Can any one help me on this ..
Thanks in advance Ganesh.
Hi Ganesh,
When you create a Document the first line is already added, you only have to add lines if you use more than one.
From the second line on you must add first the line and after that put inside the values you want to.
In your code you fill the information for the first line, then you add a second line, after that in the next loop you fill the information for the second line and add a third line... so at the end you always add a line without filling information on it.
The right code should be:
bLineAdded = False
For iCnt = 0 To vSOLines.Count - 1
If bLineAdded = True Then
vDeliveryLines.Add()
Else
vLineAdded = True
End If
vDeliveryLines.BaseType = SAPbobsCOM.BoAPARDocumentTypes.bodt_Order
vDeliveryLines.BaseEntry = sSO
vDeliveryLines.BaseLine = iCnt
Next
Hope it is clearer now
Trinidad.
User | Count |
---|---|
94 | |
11 | |
11 | |
6 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.