Showing results for 
Search instead for 
Did you mean: 

Starting with .NET - Learning and Understanding Code

0 Kudos


I'm hoping to start to learn .net for SAP B1, but finding it really had to find any books which are SAP specific. I do have the SDK Help Center file and this is great for knowing all of the objects, classes and methods, but to be honest it's really difficult to take in without a guideline as to the best way to pick up this skill.

I'm using this code as a starting point, it already exists in my database, and i understand some of it.... The 2 things i am unsure about within the code; is

company.GetLastErrorDescription,5,true - I cannot find any reference to the ,5,true anywhere within the help files.

lRetCode = oBP.Update() - and i am trying to make sense of this? from what I understand .update is a method? and when it is pressed it returns a value, = would be true? 1 would be false possibly?

Any help would be great thank you!

Dim oBP As SAPbobsCOM.BusinessPartners
Dim StopCode As String = "$[$BOY_1.StopCode.0]"
Dim lRetCode As Integer
oBP = company.GetBusinessObject(BoObjectTypes.oBusinessPartners)
If oBP.GetByKey("$[$BOY_1.BPCode.0]") = True Then
oBP.UserFields.Fields.Item("U_StopCode").Value = StopCode
oBP.UserFields.Fields.Item("U_OnHold").Value = "Y"
lRetCode = oBP.Update()
If lRetCode <> 0 Then
application.SetStatusbarMessage("BP" + "$[$BOY_1.BPCode.0]" + "cannot be updated. Error: " + company.GetLastErrorDescription,5,true)
end if
End If

Accepted Solutions (0)

Answers (2)

Answers (2)

Product and Topic Expert
Product and Topic Expert

Dear andygray123,

You can install SAP Business One SDK from the Patch Package. SAP Business One SDK contains the sample codes which you can refer and those should help you.

Refer to the Practice section in the following blog post: Take SAP Business One 10.0 Training & Certification.

Here, you can learn about SAP Business One SDK/Extensibility (Course TB1300 should be there). You can use the demo databases for SAP Business One to practice the case studies.

Regarding your other questions:

lRetCode = oBP.Update() This particular code is trying to update a Business Partner Master Data using Data Interface (DI API). BusinessPartners object is used to Add/Update/Find/Remove Business Partner Master Data.

company.GetLastErrorDescription,5,true GetLastErrorDescription() method retrieves the description of the last error issued by any object related to the Company object. However, not sure, why 5, true are passed. These appear to be some kind of parameters.

Hope it helps!

Kind regards,


SAP Business One Support

Active Contributor
0 Kudos

Hi Andrew,

Generally speaking programming with the DI API goes like this:

  1. Connect to the Company object
  2. Open the interface of the relevant B1 document, or master data, etc.
  3. Find the specific document, or business partner, etc., and change the required values. Or set at least the minimum required properties to create a new one.
  4. Use the Update method of the given object to apply the changes you assigned. Or use the Add method to create a new document.
  5. Clean up the object

In addition to what ankit.chauhan said about lRetCode = oBP.Update(), the Add, Update, and Delete methods will return 0 upon success, and the error number upon failure. Please note that the DI API error mechanism will always only return the first error it finds. So if there are multiple errors, you may have to test and correct your code multiple times.

company.GetLastErrorDescription will return a description of the most recent error thrown by your code. company.GetLastError(YourOwnIntegerVariable, YourOwnStringVariable) does the same but will assign both the error code and description to the supplied variables, which you can then use and/or show in some fashion. Simplified, something like this:

If oBP.GetByKey("$[$BOY_1.BPCode.0]") = True Then
   'The given BP number exists
   oBP.CardName = "Name-Changes-R-Us Inc."
   'Try to apply the value
   If oBP.Update = 0 Then
      MsgBox(SBO.vCmp.GetLastErrorCode() & " - " & SBO.vCmp.GetLastErrorDescription())
   End If
End If