EventFilters and EventFiltrer object in SAP B1 filtering the event for the specific form

EventFilters and EventFilrer object in SAP B1:

EventFilters and EventFiltrer object in SAP B1 filtering the event for the specific form. In this post, I will describe you about EventFilters & EventFiltrer object in SAP B1 and how to filter the event for the specific form of SAP B1. By default, every event is triggered by SAP Business one application. We can filter only required events on the specific form by the EventFilters collection object and EventFilter object.Therefore it enhances the performance of our application by applying only required events.So we can say that this object lets you filter events for your addon and also specify which event should apply on which form.

How to filter the event through the code:

I have made a simple class for doing this events filteration kindly go through  line by line.

using System;
namespace FilterEvents
{
    public class EventFilterEx
    {
        private SAPbouiCOM.Application SBO_Application;


        // I have declaring an Event filters container object and an event filter object
        public SAPbouiCOM.EventFilters oFilters;
        public SAPbouiCOM.EventFilter oFilter;

        private void SetFiltersMethod()
        {

            // Creating a EventFilters object
            oFilters = new SAPbouiCOM.EventFilters();

            // adding an event type to the container this method returns an EventFilter object
            oFilter = oFilters.Add(SAPbouiCOM.BoEventTypes.et_CLICK);

            // assigning the form type on which the event will be processed
            oFilter.AddEx( “139” ); // Orders Form
            oFilter.AddEx( “142” ); // Purchase Form

            oFilter = oFilters.Add(SAPbouiCOM.BoEventTypes.et_KEY_DOWN);

            // assigning the form type on which the event will be processed
            oFilter.Add(139); // Orders Form

            // For a list of all form types you can use the Tools -> User Tools -> Display Debug Information option in the SBO application then open the desired form and hover over it with the mouse the form’s type will apear in the lower left side of the screen
            // After Setting the application with the EventFilters object in this case we will process a click event for form types 142 and 139 and we will process a key down event for for form type 139

            SBO_Application.SetFilter(oFilters);

        }

        public EventFilterEx()
        {

            //Calling this function for creating the connection with sap b1
            //and the body of this function i have defined on my another post hence i am giving the hyperlink
            SetConnection();



            //this function will set the events to be filter.
            SetFiltersMethod();

            //These are the events will be used by your addon and the definition of these events are given below.
            // events handled by SBO_Application_AppEvent
            SBO_Application.AppEvent += new SAPbouiCOM._IApplicationEvents_AppEventEventHandler(SBO_Application_AppEvent);
            // events handled by SBO_Application_MenuEvent
            SBO_Application.MenuEvent += new SAPbouiCOM._IApplicationEvents_MenuEventEventHandler(SBO_Application_MenuEvent);
            // events handled by SBO_Application_ItemEvent
            SBO_Application.ItemEvent += new SAPbouiCOM._IApplicationEvents_ItemEventEventHandler(SBO_Application_ItemEvent);
        }

        private void SBO_Application_AppEvent(SAPbouiCOM.BoAppEventTypes EventType)
        {

            switch (EventType)
            {
                case SAPbouiCOM.BoAppEventTypes.aet_ShutDown:

                    SBO_Application.MessageBox( “A Shut Down Event has been caught” +Constants.vbNewLine + “Terminating Add On…”, 1, “Ok”, “”, “” );
                    System.Environment.Exit(0);

                    break;
                case SAPbouiCOM.BoAppEventTypes.aet_CompanyChanged:

                    SBO_Application.MessageBox( “A Company Change Event has been caught”, 1, “Ok”, “”, “” );

                    break;
                case SAPbouiCOM.BoAppEventTypes.aet_LanguageChanged:

                    SBO_Application.MessageBox( “A Languge Change Event has been caught”, 1, “Ok”, “”, “” );
                    break;
            }

        }

        private void SBO_Application_MenuEvent(ref SAPbouiCOM.MenuEvent pVal, out bool BubbleEvent)
        {

            //When we make BubbleEvent true then application allow you to perform your event or execute your code written inside the event.
            //When it is false that means Application is not going to excute your code written inside the event.
            //BubbleEvent true means application allow us to perform event by own false means they dont allow to perform event by you.
            BubbleEvent = true;
            if (pVal.BeforeAction == true)
            {

                SBO_Application.SetStatusBarMessage( “Menu item: ” +pVal.MenuUID + ” sent an event BEFORE SAP Business One processes it.”, SAPbouiCOM.BoMessageTime.bmt_Long, true );

        // to stop SAP Business One from processing this event
        // unmark the following statement

        // BubbleEvent = True

            }
            else
             {

              SBO_Application.SetStatusBarMessage( “Menu item: ” + pVal.MenuUID + ” sent an event AFTER SAP Business One processes it.”, SAPbouiCOM.BoMessageTime.bmt_Long, true );

             }

        }

        private void SBO_Application_ItemEvent(string FormUID, ref SAPbouiCOM.ItemEvent pVal, out bool BubbleEvent)
        {

            BubbleEvent = true;

            // BubbleEvent sets the behavior of SAP Business One.
            // False means that the application will not continue processing this event
            // True is the default value

            if (pVal.FormType != 0 & pVal.Before_Action == true)
            {

                switch (pVal.EventType)
                {
                    case SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED:

                        // Specifies a button release (After exit).

                        SBO_Application.MessageBox( “An et_ITEM_PRESSED has been sent by a form with the unique ID: ” +FormUID, 1, “Ok”, “”, “” );

                        break;
                    case SAPbouiCOM.BoEventTypes.et_KEY_DOWN:

                        // Specifies a key down event.

                        SBO_Application.MessageBox( “An et_KEY_DOWN has been sent by a form with the unique ID: ” +FormUID, 1, “Ok”, “”, “” );

                        break;
                    case SAPbouiCOM.BoEventTypes.et_GOT_FOCUS:

                        // Specifies an item got focus.

                        SBO_Application.MessageBox( “An et_GOT_FOCUS has been sent by a form with the unique ID: ” +FormUID, 1, “Ok”, “”, “” );

                        break;
                    case SAPbouiCOM.BoEventTypes.et_LOST_FOCUS:

                        // Specifies an item lost focus.

                        SBO_Application.MessageBox( “An et_LOST_FOCUS has been sent by a form with the unique ID: ” +FormUID, 1, “Ok”, “”, “” );

                        break;
                    case SAPbouiCOM.BoEventTypes.et_COMBO_SELECT:

                        // Specifies the selection of valid value in Combo Box.

                        SBO_Application.MessageBox( “An et_COMBO_SELECT has been sent by a form with the unique ID: ” +FormUID, 1, “Ok”, “”, “” );

                        break;
                    case SAPbouiCOM.BoEventTypes.et_CLICK:
                        // Specifies Mouse Up on editable item.

                        SBO_Application.MessageBox( “An et_CLICK has been sent by a form with the unique ID: ” +FormUID, 1, “Ok”, “”, “” );

                        break;
                    case SAPbouiCOM.BoEventTypes.et_DOUBLE_CLICK:
                        // Specifies Mouse Up on editable item in time interval define by
                        // SAP Business One as double-click.

                        SBO_Application.MessageBox( “An et_DOUBLE_CLICK has been sent by a form with the unique ID: ” +FormUID, 1, “Ok”, “”, “” );

                        break;



                    case SAPbouiCOM.BoEventTypes.et_MATRIX_LINK_PRESSED:
                        // Specifies a link arrow within a matrix was pressed.

                        SBO_Application.MessageBox( “An et_MATRIX_LINK_PRESSED has been sent by a form with the unique ID: ” +FormUID, 1, “Ok”, “”, “” );

                        break;
                    case SAPbouiCOM.BoEventTypes.et_MATRIX_COLLAPSE_PRESSED:
                        // Specifies collapsed or expanded list within a matrix.

                        SBO_Application.MessageBox( “An et_MATRIX_COLLAPSE_PRESSED has been sent by a form with the unique ID: ” +FormUID, 1, “Ok”, “”, “” );

                        break;
                    case SAPbouiCOM.BoEventTypes.et_VALIDATE:
                        //Specifies an item validation event.

                        SBO_Application.MessageBox( “An et_VALIDATE has been sent by a form with the unique ID: ” +FormUID, 1, “Ok”, “”, “” );

                        break;
                    case SAPbouiCOM.BoEventTypes.et_FORM_LOAD:
                        // Specifies that SAP Business One application opened a form.

                        SBO_Application.MessageBox( “An et_FORM_LOAD has been sent by a form with the unique ID: ” +FormUID, 1, “Ok”, “”, “” );

                        break;
                    case SAPbouiCOM.BoEventTypes.et_FORM_UNLOAD:
                        // Specifies that SAP Business One application closed a form.

                        SBO_Application.MessageBox( “An et_FORM_UNLOAD has been sent by a form with the unique ID: ” +FormUID, 1, “Ok”, “”, “” );

                        break;
                    case SAPbouiCOM.BoEventTypes.et_FORM_ACTIVATE:
                        // Specifies that the focus is set on the form.

                        break;
                    case SAPbouiCOM.BoEventTypes.et_FORM_DEACTIVATE:

                        break;
                    case SAPbouiCOM.BoEventTypes.et_FORM_CLOSE:

                        SBO_Application.MessageBox( “An et_FORM_CLOSE has been sent by a form with the unique ID: ” +FormUID, 1, “Ok”, “”, “” );

                        break;
                    case SAPbouiCOM.BoEventTypes.et_FORM_RESIZE:

                        SBO_Application.MessageBox( “An et_FORM_RESIZE has been sent by a form with the unique ID: ” +FormUID, 1, “Ok”, “”, “” );

                        break;
                    case SAPbouiCOM.BoEventTypes.et_FORM_KEY_DOWN:

                        SBO_Application.MessageBox( “An et_FORM_KEY_DOWN has been sent by a form with the unique ID: ” +FormUID, 1, “Ok”, “”, “” );

                        break;
                }
            }
}

 

This class will startup of the application.

using System;
namespace FilterEvents {
class SubMain {
public static void Main() {
EventFilterEx oEventsFilter = null;
oEventFilter = new EventFilterEx();
System.Windows.Forms.Application.Run();
}
}
}


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!