Skip to Content
avatar image
Former Member

Create Order Not Working

Dear experts,

I have recently started learning to code in SDK so please pardon my basic question and programming stupidity.

I have created a button on a UDO (using B1Up add-on). That will create a sales order. Its a simple code, given below, but is failing.

Can you please advise what is wrong?

Errors are:

Line: 14 - Type 'SAPbobsCOM.Documents.Lines' is not defined.
Line: 17 - Name 'oOrders' is not declared.

Code is:

Imports System
Imports SAPbobsCOM
Imports SAPbouiCOM
Namespace ROGERNAME
    Public Class ROGERCLASS
        Public Function DynamicCode(ByVal ParamArray parameters() As Object) As String
            Dim company As SAPbobsCOM.Company = parameters(0)
            Dim application As SAPbouiCOM.Application = parameters(1)
            Dim form As SAPbouiCOM.Form = parameters(2)
            Dim eventForm As SBO.UI.B1Form = parameters(3)
            Dim eventData As [Shared].Model.DotNetEventObject = DirectCast(parameters(4), [Shared].Model.DotNetEventObject)
            Dim addonData As SBO.AddonLogic.AddonData = parameters(5)
            Dim oOrder As SAPbobsCOM.Documents
            Dim oOrderLine As SAPbobsCOM.Documents.Lines
            Dim oCompany As SAPbobsCOM.Company
            oOrder = oCompany.GetBusinessObject(oOrders)
            oOrder.CardCode = "10195"
            oOrder.DocDate = "20151030"
            oOrderLine.ItemCode = "BSG1273AV52600CB"
            oOrderLine.Quantity = 5
            oOrder.Add
        End Function
    End Class
End Namespace

Thanks in advance.

Best Regards

K

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Nov 02, 2015 at 12:54 PM

    Hi Kanu,

    Could you try changing Line 14 and Line 16 as follows;

          

    Line 14: Dim oOrderLine As SAPbobsCOM.Document_Lines

    Line 16: oOrder = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders)

    Regards,
    Atilla

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Kanu,

      I didn't understand the error but I can see two missing point in your code. First you have to enter "DocDueDate" mandatorly also you should enter both "DocDueDate" and "DocDate" as Date variable not string.


      Also try getting last error description from "oCompany" object so that we can have a better understanding of the error.

      Here is a sample code about how you can create order and get last error description from "oCompany" object;

             Dim oOrder As SAPbobsCOM.Documents

              Dim oOrderLine As SAPbobsCOM.Document_Lines

              Dim ret As Integer

              Dim oCompany As SAPbobsCOM.Company

              oCompany = New SAPbobsCOM.Company

              oCompany.Server = "servername"

              oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2012

              oCompany.CompanyDB = "companydb"

              oCompany.UserName = "username"

              oCompany.Password = "password"

              oCompany.Connect()

              oOrder = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders)

              oOrder.CardCode = "C20000"

              oOrder.DocDate = Today

              oOrder.DocDueDate = Today

              oOrderLine = oOrder.Lines

              oOrderLine.ItemCode = "A00004"

              oOrderLine.Quantity = 5

              oOrderLine.Add()

              ret = oOrder.Add()

              If ret = 0 Then

                  MessageBox.Show("Success")

              Else

                  MessageBox.Show(oCompany.GetLastErrorDescription.ToString())

              End If

      I hope this helps.

      Regards,

      Atilla





  • Nov 02, 2015 at 12:42 PM

    Hi Kanu,

    These errors occurs in compile execution or at runtime?

    Regards,

    Diego

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 02, 2015 at 02:11 PM

    Hi Kanu,

    Make the changes proposed by , and you'll also need to add oOrderLine = oOrder.Lines after line 16.


    Best regards,

    Pedro Magueija


    View Pedro Magueija's profile on LinkedIn

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Where is this DynamicCode function being called from? An "exception being thrown by the target of an invocation" usually means that there's an asynchronous call to a process out there somewhere that's failing, and when it finally returns back, it reports an error. I think we need more context on when, where, and how you're calling this function.