on 07-02-2021 8:29 AM
Hi,
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
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,
ANKIT CHAUHAN
SAP Business One Support
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Andrew,
Generally speaking programming with the DI API goes like this:
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
'Success
Else
'Failure
MsgBox(SBO.vCmp.GetLastErrorCode() & " - " & SBO.vCmp.GetLastErrorDescription())
End If
End If
Regards,
Johan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
110 | |
12 | |
11 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.