cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Create new document using SDK

Former Member
0 Likes
1,073

Hello!

Could you please answer to my question?

Does anybody have SDK-code example (VB, C#), which creates new document in SAPb1. Something like this:

http://www.youtube.com/watch?v=tWEnK4WUQ64

Is it possible in default version of SDK? What documentation shoud I read?

View Entire Topic
Former Member
0 Likes

Hi,

see this path in your system,

C:\Program Files\SAP\SAP Business One SDK\Samples

Regards,

Siva

Former Member
0 Likes

I've checked DI and UI examples and documentation and have found a working code example.

My last question: How can i get the SAP number of created document? Is it possible, does any property or method of document class exist?

Or I have to create user column "number" in Sap and find my docs using this column?

Working VB-code example:

Dim oOrder As New SAPbobsCOM.Documents ' Order object

        Dim lRetCode As Integer ' Return Code

        ' New Order
        Set oOrder = oCompany.GetBusinessObject(SAPbobsCOM.oOrders)

        ' Fill Order details
        oOrder.CardCode = "C40000"
        oOrder.CardName = "Earthshaker Corporation"
        oOrder.HandWritten = SAPbobsCOM.BoYesNoEnum.tNO
        oOrder.DocDate = Now()
        oOrder.DocDueDate = Now()
        oOrder.DocCurrency = "USD"

        'Fill 2 lines in the order
        oOrder.Lines.ItemCode = "A00001"
        oOrder.Lines.ItemDescription = "IBM Inforprint 1312"
        oOrder.Lines.Quantity = 1
        oOrder.Lines.Price = 380
        oOrder.Lines.TaxCode = "0"
        oOrder.Lines.LineTotal = 380

        oOrder.Lines.Add
        
        oOrder.Lines.ItemCode = "A00002"
        oOrder.Lines.ItemDescription = "IBM Infoprint 1222"
        oOrder.Lines.Quantity = 1
        oOrder.Lines.Price = 380
        oOrder.Lines.TaxCode = "0"
        oOrder.Lines.LineTotal = 380

        ' Now we want to delete the second line in the Order
        oOrder.Lines.Delete

        ' The Order will be added without the second line
        lRetCode = oOrder.Add
        If lRetCode <> 0 Then
            oCompany.GetLastError lErrCode, sErrMsg
            MsgBox "Error ¹" & lRetCode & sErrMsg
        Else
            MsgBox "Norm"
        End If

Former Member
0 Likes

Is that the only way to find Order Number: find max(OrderNum) + 1 before creating order:

	Dim sSQL = "SELECT TOP 1 DocNum FROM dbo.ORDR ORDER BY DocNum DESC"
        rs = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
        rs.DoQuery(sSQL)
	txtNo.Text = rs.Fields.Item(0).Value + 1

And after that create an order:

oOrder.DocNum = txtNo.Text

This is the way, but I think it is no t clear (in case many sessions in the same time).

Former Member
0 Likes

Yes. This is the only way. You may not have ability to detect any other users try to do the same. Better restrict the usage of the add-on to make sure not in conflict with others.

Former Member
0 Likes

GordonDu,

Thank you very much!

No more questions.

According to this forum, it is the only correct way:

Topic can be closed.

Former Member
0 Likes

I get the BP number and look for the last document created for this BP. The chances of more than one document being added for the same BP is small.