cancel
Showing results for 
Search instead for 
Did you mean: 

oForm.BusinessObject raises COMException / E_NOINTERFACE: No such interface supported

rajesh_khater
Active Participant
0 Kudos

I am getting the following COMException in oForm.BusinessObject:

Unable to cast COM object of type 'System.__ComObject' to interface type 'SAPbobsCOM.Documents'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{A6DA575B-E105-4585-9F4B-50CC4044EEDD}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).


Scenario:

The AR Invoice screen is in Ok Mode, and the data is already loaded by the user by browsing using the record navigation keys on the toolbar. On click of a button, I need to update a header level UDF in the currently loaded document.

My code:

private void Update_UDF_In_Current_Document(string FormUID, string dataSourceName, int docEntry, string udfName, string udfValue)

{

SAPbobsCOM.Documents arInvoice = null;

SAPbouiCOM.Form oForm = null;

oForm = oSboApplication.Forms.Item(FormUID);

arInvoice = (SAPbobsCOM.Documents)oForm.BusinessObject;

//some more code

}

I am getting Exception in the line:

arInvoice = (SAPbobsCOM.Documents)oForm.BusinessObject;

Workaround:

I am able to update the document using:

arInvoice = oCompany.GetBusinessObject(BoObjectTypes.oInvoices);
arInvoice.GetByKey(docEntry);


and then some additional lines of code to update the header level UDFs.


Question:

When the AR Invoice form is already loaded with data on the screen, why does Form.BusinessObject not work? Why am I forced to get the business object data using GetByKey(). Is it not possible to avoid the call to GetByKey(), which in turn will make a database call?


The SAP B1 version is 10.0 FP 2202 (technical version 10.00.190)

Accepted Solutions (0)

Answers (1)

Answers (1)

Johan_H
Active Contributor
0 Kudos

Hi,

The workaround arInvoice = oCompany.GetBusinessObject(BoObjectTypes.oInvoices); you mentioned is actually the correct way to do it. Unfortunately the SDK does not do short cuts or implied.

The Documents interface covers all types of documents, and you must specify which type of document you want.

The GetByKey method is only necessary when you need to update or close an object. Pointer: it returns a boolean. True when the object is found, and False when not.

Regards,

Johan

rajesh_khater
Active Participant
0 Kudos

I found this in the UI API reference. Seems like BusinessObject property is relevant only for user-defined forms, and moreover it seems to refer to the UDO object associated with the Form.

Johan_H
Active Contributor
0 Kudos

The BusinessObject property of a User Defined Object is not the same thing as the BusinessObject in GetBusinessObject(BoObjectTypes.oInvoices).