Search code examples
c#sapb1sap-business-one-di-api

How do I catch the item event in SAP B1 after all elements on a form have loaded?


I am creating an addon in SAP Business One and I need to fill a matrix with data as soon as the form loads.

I have the following code:

private void Application_ItemEvent(string FormUID, ref SAPbouiCOM.ItemEvent pVal, out bool BubbleEvent)
{
    BubbleEvent = true;

    try
    {
        (pVal.FormTypeEx == "UDO_FT_CASHBOOK" && pVal.EventType == SAPbouiCOM.BoEventTypes.et_FORM_LOAD && pVal.BeforeAction == false)
            {
                SAPbobsCOM.Recordset rs = (SAPbobsCOM.Recordset)SboConnection.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);

                ...more code...
                
                oform = SboConnection.SboApplication.Forms.ActiveForm;

                // Get matrix
                oItem = oform.Items.Item("0_U_G"); <----------------error thrown: 
                oMatrix = (SAPbouiCOM.Matrix)(oItem.Specific);

Error gets thrown at the above line because that item element does not exist yet.

How do I get to fill matrix data as soon as the form has loaded?


Solution

  • when i encountered this problem, using:

    SAPbouiCOM.BoEventTypes.et_FORM_VISIBLE
    

    instead of

    SAPbouiCOM.BoEventTypes.et_FORM_LOAD
    

    corrected the issue.