Skip to Content
author's profile photo Former Member
Former Member

Add new line to Sales Order

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!

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 17, 2005 at 07:00 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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

  • author's profile photo Former Member
    Former Member
    Posted on Jan 18, 2005 at 09:28 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 18, 2005 at 09:47 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.