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

Create new document using SDK

Former Member
0 Likes
1,072

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?

Accepted Solutions (1)

Accepted Solutions (1)

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.

Answers (1)

Answers (1)

Former Member
0 Likes

Hi,

Welcome you post on the forum.

The video is not for B1. It is for R3. You can find all sample codes from SDK help folder. Have you checked?

Thanks,

Gordon

Former Member
0 Likes

Ok, thank you,

I will check every example. If i find an answer i'll write here.

Former Member
0 Likes

I didn't find and example (SDK UI).

The author of that video wrotes:

"

This macro writen in VBA. Using SAP B1 UI API you can reach any object of the system (User defined object also). This is indirect interaction. Just push a button and the datas from excel spreedshet gettin' into SAP Business One.

"

Is that true? Or I need to buy license for DI? Can I create a new order using SDK UI? I really can't understand.

Former Member
0 Likes

Only UI is not good enough. DI is must. However, I don't think you need any extra license for DI API. Only DI Server may need special license.

Thanks,

Gordon