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

To access DI API while opening SAP Business One, which method should I use?

Peach14
Explorer
0 Likes
568

I'm trying to create an Add-On with C# for SAP Business One.

I've known that if the Add-On executed without SAP Application opening, I need to manually set company information to connect to the database. 

But if SAP Application is opening, I've known that we can use the connection from UI API and set it to DI API.

I've known 2 methods of it but not sure which method to be used and why it's more efficient.

Method 1

 

SAPbobsCOM.Company oCompany = new SAPbobsCOM.Company();
string cookie = oCompany.GetContextCookie();
string connectionContext = oApp.Company.GetConnectionContext(cookie);
oCompany.SetSboLoginContext(connectionContext);
oCompany.Connect();

 

Method 2

 

SAPbobsCOM.Company oCompany = (SAPbobsCOM.Company)oApp.Company.GetDICompany();

 

I've found that Method 2 is easier but not sure if there is any limitations or cautions on it.

Please enlighten me. Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

williamwachholz
Active Participant

Hello,

 

Check the below thread, it have a long discussion about this topic:

 

https://community.sap.com/t5/enterprise-resource-planning-q-a/getdicompany-performance-issue/qaq-p/9...

 

Best regards

Peach14
Explorer
0 Likes
Thanks!

Answers (0)