cancel
Showing results for 
Search instead for 
Did you mean: 

Create Order Not Working

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

former_member183373
Active Participant
0 Kudos

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

Former Member
0 Kudos

Hi Atilla,

Thanks for your help.

The program compiled properly but on execution throws this error:

Error in DotNetCode: Exception has been thrown by the target of an invocation.

Looks quite obnoxious. Any clue?

Thanks & Regards

K

former_member183373
Active Participant
0 Kudos

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





Answers (2)

Answers (2)

pedro_magueija
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hi Pedro,

Still same error at the execution:

Error in DotNetCode: Exception has been thrown by the target of an invocation.

The code compiles ok.

Any idea?

Thanks & Regards

K

Former Member
0 Kudos

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.

former_member185682
Active Contributor
0 Kudos

Hi Kanu,

These errors occurs in compile execution or at runtime?

Regards,

Diego