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)