Search code examples
sdksapb1

Would like to learn SAP Business One development and to use the SDK


I would like to know how to code for SAP B1 but where do I start and I would like a simple explanation. Ideally in VB.net.


Solution

  • If you have SAP and the SDK installed Samples can be found here:

    C:\Program Files (x86)\SAP\SAP Business One SDK\Samples\COM DI\VB.NET
    

    a simple piece of DI-API Code to update a Sales opportunity might look like this:

            Private Function updateOpportunity(docEntry, type, value) As Boolean
    
            'updates either interest or status on linked opportunity
            'returns true if successful
            Dim oCompany As SAPbobsCOM.Company = Application.SBO_Application.Company.GetDICompany
            Dim oppToUpdate As SAPbobsCOM.SalesOpportunities = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oSalesOpportunities)
    
            oppToUpdate.GetByKey(docEntry)
    
            If type = "Interest" Then
                oppToUpdate.InterestLevel = value
            ElseIf type = "Status" Then
                oppToUpdate.Status = value
            End If
    
            If oppToUpdate.Update() <> 0 Then
                Return False
            Else
                Return True
            End If
    
        End Function
    

    and here a simple example to add lines to a sales order:

     Try
    
       Dim objCompany As SAPbobsCOM.Company = CType(Application.SBO_Application.Company.GetDICompany, SAPbobsCOM.Company)
        
                        objOrder = CType(objCompany.GetBusinessObject(docType), SAPbobsCOM.Documents)
                        objOrder.GetByKey(123456)           
                            'Add Rows     
                        With objOrder.Lines             
    
                                'adds a blank row to order
                                .Add()
    
                                'insert all the data
                                .ItemCode = "myItemCode"
                                .Quantity = 20
                                .UnitPrice = 2.50 
    
                        'save changes / test success 
                       dim intResult = CByte(objOrder.Update())    
                
                        If intResult = 0 Then
                           Application.SBO_Application.SetStatusBarMessage("Rows Added Successfully", SAPbouiCOM.BoMessageTime.bmt_Short, False)                    
                        End If
                     
                    Catch ex As Exception
                        Application.SBO_Application.MessageBox("Add lines Failed  " & objCompany.GetLastErrorDescription)
                    End Try
               
            End Sub