cancel
Showing results for 
Search instead for 
Did you mean: 

How to copy Sales Order to A/R Invoice (or at least set the BaseRef)

tjandra_afandi2
Participant
0 Kudos

Hi, currently if I need to 'convert' a Sales Order into A/R Invoice, I have to do it via the SAP application directly. What I'm trying to achieve is to automatically do it via an EXE application (I have one ready for other purpose -> connect to SAP via DI).

So far I know how to create a new A/R Invoice and close the Sales Order, but the problem is that I can't 'link' the Invoice to the original Sales Order (ie. the BaseRef field). Is there a way to do it?

Furthermore, is there any easier way? ie. simply call a 'copy' method or something else, instead of writing the same information (field by field) from Sales Order to Invoice?

Please advise.

Thanks.

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Tjandra,

I want to copy those SO to Invoice. May I have the VB coding for doing this?

Thanks

Former Member
0 Kudos

Just to be absolutely clear:

If you are creating an A/R Invoice through the DI API, I know of no easy way to copy a Sales Order. You have to copy all properties and in particular the base properties mentioned in an earlier post.

Former Member
0 Kudos

Hello

You need to set the base properties on each line in the A/R Invoice

line.BaseEntry = (DocEntry of Sales Order);
line.BaseType = BoLinkedObject.lf_Order;
line.BaseLine = (the line number from the Order);

Unfortunately there is no "CopyTo" function available, that would indeed have been nice.

Regars

/Martin

Former Member
0 Kudos

Hi Afandi,

This will solve your problem

Private Sub CreateInvoice()
        ' init the invoice object
        oInvoice = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices)
        oInvoice.CardCode = cmbCustomer.Text

        Dim sNewObjCode As String
        Dim i As Integer
        ' Get last added document number (the order that was added)
        oCompany.GetNewObjectCode(sNewObjCode)

        ' this loop adds the different items to the invoice object
        i = 0
        Do
            oInvoice.Lines.BaseEntry = sNewObjCode
            oInvoice.Lines.BaseLine = i
            oInvoice.Lines.BaseType = SAPbobsCOM.BoObjectTypes.oOrders
            oInvoice.Lines.TaxCode = TableLines.Rows(i).Item(4)
            i += 1
            If i <> TableLines.Rows.Count Then
                oInvoice.Lines.Add()
            End If
        Loop Until i = TableLines.Rows.Count

        ' Try to add the invoice object to the database
        lRetCode = oInvoice.Add()
        If lRetCode <> 0 Then ' If the addition failed
            oCompany.GetLastError(lErrCode, sErrMsg)
            MsgBox(lErrCode & " " & sErrMsg) ' Display error message
        Else
            cmdInvoice.Enabled = True
            MsgBox("inv Added to DataBase", MsgBoxStyle.Information, "Order Added")
        End If

Mohamed

tjandra_afandi2
Participant
0 Kudos

Thanks Mohamed, but looks like your code is simply creating a new A/R invoice?

My problem is with copying Sales Order to A/R Invoice.

Thanks.

Former Member
0 Kudos

With the DI, this is how you do it - but the DI pulls the information from the base lines unless you specifically change it, so you only have to set the header information manually.