Kinyanjui Kamau
Kinyanjui Kamau

Reputation: 1926

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?

Upvotes: 0

Views: 1878

Answers (1)

Praxiom
Praxiom

Reputation: 646

when i encountered this problem, using:

SAPbouiCOM.BoEventTypes.et_FORM_VISIBLE

instead of

SAPbouiCOM.BoEventTypes.et_FORM_LOAD

corrected the issue.

Upvotes: 0

Related Questions