on 01-17-2005 5:39 PM
Hi everybody!!
I am doing some data importation into SBO. I run have some problems adding new lines to sales orders. Here is the code.
With SBOOrder.Lines
.Add
.ItemCode = MaterialNode.selectSingleNode("ItemNo").Text
.WarehouseCode = MaterialNode.selectSingleNode("StoreNo").Text
.ShipDate = MaterialNode.selectSingleNode("Date").Text
.ItemDescription = MaterialNode.selectSingleNode("Description").Text
.PriceAfterVAT = MaterialNode.selectSingleNode("VATRate").Text
.Price = MaterialNode.selectSingleNode("CustomerPrice").Text
.Quantity = MaterialNode.selectSingleNode("Quantity").Text
.BaseType = 17
End With
lRetCode = SBOOrder.Update
With this code I get "Base Doc Missmatch" error. It is obvious that some fields need to fill up before adding the new line. But I don't know witch! I haven't found any example of document lines creation. Could anybody post an example?
Thanks in advance!
I think with your code you are creating 2 Order lines.
Try call .Add at the end of the code
With SBOOrder.Lines
'.Add
.ItemCode = MaterialNode.selectSingleNode("ItemNo").Text
.WarehouseCode = MaterialNode.selectSingleNode("StoreNo").Text
.ShipDate = MaterialNode.selectSingleNode("Date").Text
.ItemDescription = MaterialNode.selectSingleNode("Description").Text
.PriceAfterVAT = MaterialNode.selectSingleNode("VATRate").Text
.Price = MaterialNode.selectSingleNode("CustomerPrice").Text
.Quantity = MaterialNode.selectSingleNode("Quantity").Text
'.BaseType = 17 -
> use SAPbobsCOM.BoAPARDocumentTypes.bodt_Order instead of hardcoded numbers, this prevents errors on new versions
.BaseType = SAPbobsCOM.BoAPARDocumentTypes.bodt_Order
End With
'lRetCode = SBOOrder.Update
lRetCode = SBOOrder.Add
Hope this help you,
Ribeiro Santos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Let's try to do it a little bit clearer,
According to your code sample in the original message, there are two things that you have to pay attention to:
1) <u>Adding line to a document</u>
a new instance of a document object is being created with one empty line as default, which means that you do not have to call the Add method of the Document_Lines object for the first line (as Jacques mentioned)
Set oDoc = oCompany.GetBusinessObject(oOrders)
oDoc.CardCode = "1903"
oDoc.DocDate = Date
'.................... more header properties
'no need to add the first line
oDoc.Lines.ItemCode = "A00001"
oDoc.Lines.Quantity = 10
'.................... more row properties
oDoc.Lines.Add 'Adding the second line before assigning values to properties
oDoc.Lines.ItemCode = "A00002"
oDoc.Lines.Quantity = 20 '.................... more row properties
lRetCode = oDoc.Add
If lRetCode <> 0 Then
oCompany.GetLastError lErrCode, sErrMsg
MsgBox "Failed to add the document " & vbNewLine & sErrMsg
Else
oCompany.GetNewObjectCode sNewObjCode
MsgBox "Invoice was added successfuly" & vbNewLine & "invoice number " & sNewObjCode
End If
2) <u>Basing a Document line on another document</u>
in order to create a line in a document that is base on a former document (e.g. Sales Order that is based on a quotation) it is necessary to use a combination of 3 properties of the Document_Lines object
- <b>BaseType</b> the type (quotation, sales order, delivery note ..) of the existing document that we would like to withdraw a line from
- <b>BaseEntry</b> the unique key of the existing document that we would like to withdraw a line from
note that the unique key of a document <u>is not DocNum</u> but <b>DocEntry</b>
- <b>BaseLine</b> the corresponding line in the base document (zero based)
'....................
oDoc.Lines.BaseType = BoAPARDocumentTypes.bodt_Quotation
oDoc.Lines.BaseEntry = 135
oDoc.Lines.BaseLine = 1
'....................
the code above means that the new line that was created will take all its values from line no 1 (the second line) an existing quotation document, which its DocEntry is 135
when you use only those 3 properties all the other proper tires will be initialized with values from the base line, any assignment of addition property (e.g oDoc.Lines.Quantity=2) will overwrite the value from the base line
In your original message you are creating a line in a Sales Order, and you are trying to base it on a sales order (.BaseType=17) this assignment is meaningless
Regards, Avi.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Jose,
Which Business One and SDK version are you using?
is the original order based on other documents?
please try to remove the code line:
.BaseType = 17
Regards, Avi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
When you use basetype and basedoc, SBO will try to check this on a per-line basis. You get this (or a similar) error if this check fails. So if you're adding lines manually, leave those two out.
According to SBO support there is no other way to relate document(-lines) to each other, so if you would like to somehow reflect the origin of this line you're in bad luck.
Regards,
Jacques
Thanks to you two!
Avi, I am using SDK 2004. I set BaseType=17 because that's how it was in other lines in the database. Otherwise I get "Item no. is missing [ORDR.ObjType]" error when I remove the BaseType line.
Once again, it is obvious that I need to fill some other parameters in the line object, but the error message doesn't give me a clue. The other examples of adding lines that I have seen are pretty simple and they were supposed to work.
Any suggestions?
Well, you asked for an example. I'm using this code in production... (It's creating purchase lines, but they're document lines as well).
Dim oSboPurchaseLines As Document_Lines
Set oSboPurchaseLines = oSboPurchase.Lines
oSboPurchaseLines.SetCurrentLine (0)
'oSboPurchase.Lines.Add 'first line does not have to be added?!
oSboPurchaseLines.ItemCode = strPurchArt
oSboPurchaseLines.Quantity = 1
oSboPurchaseLines.Price = Round(CDbl(strAmount), 2)
oSboPurchaseLines.FreeText = "betreft " & strBrutoAantal & " vellen"
' DOES NOT WORK:
' oSboPurchase.Lines.BaseEntry = oSboOrder.DocNum
' oSboPurchase.Lines.BaseLine = 1 '<= always: calc
' oSboPurchase.Lines.BaseType = oOrders
'oSboPurchase.Lines.WarehouseCode = ""
lngRetVal = oSboPurchase.Add
If lngRetVal = 0 Then
Call oSboCompany.GetNewObjectCode(strNewId)
As you can see, I wanted to relate these lines to a basedocument as well, but had to drop that. This is 6.5 btw!!
And yes, this actually does work.
Regards,
Jacques
User | Count |
---|---|
92 | |
11 | |
11 | |
6 | |
6 | |
4 | |
3 | |
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.