cancel
Showing results for 
Search instead for 
Did you mean: 

Add a menu option in right click menu in BP Master

rajesh_khater
Active Participant
0 Kudos

Hi,

I need to add a menu option in right click menu of BP master, and on click of that menu, run a User Defined Query (query can be hardcoded).

How to do this? Can I get sample code.

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi,

In your code.

Please write the above code...

in Right click event

========================================

        Try

            Dim x As Integer

            Dim foundG As Boolean = False

            For x = 0 To SBO_Application.Forms.Count - 1

                If SBO_Application.Forms.Item(x).Type = "134" Then

                    foundG = True

                    Exit For

                End If

            Next

            If foundG = True Then

                oForm = SBO_Application.Forms.ActiveForm

              

                Try

                    Dim omenus As SAPbouiCOM.Menus

                    Dim omenuitem As SAPbouiCOM.MenuItem

                    Dim oCreationPackage As SAPbouiCOM.MenuCreationParams

                    oCreationPackage = SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_MenuCreationParams)

                    oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_STRING

                    omenuitem = SBO_Application.Menus.Item("1280") 'Data'

                    'If Not omenuitem.SubMenus.Exists("delrow") Then

                    oCreationPackage.UniqueID = "Open Emp Master"

                    oCreationPackage.String = "Open Emp Master"

                    oCreationPackage.Enabled = True

                    omenus = omenuitem.SubMenus

                    If Not omenuitem.SubMenus.Exists("Open Emp Master") Then

                        omenus.AddEx(oCreationPackage)

                    End If

                Catch ex As Exception

                    SBO_Application.MessageBox(ex.Message)

                End Try

            End If

        Catch ex As Exception

            SBO_Application.MessageBox(ex.Message)

        End Try

    End Sub

=============================================================

in menu event

        Try

            If pVal.BeforeAction = False Then

                Select Case pVal.MenuUID

                    Case "Open Emp Master"

                        oForm = SBO_Application.Forms.ActiveForm

                        oForm = SBO_Application.Forms.GetFormByTypeAndCount("134", 1)

                            '' Here u can do what ever u wnat

                            ' if u want to run query using recordset object run the query...

                            End Select

            End If

        Catch ex As Exception

            SBO_Application.MessageBox(ex.Message)

        End Try

rajesh_khater
Active Participant
0 Kudos

Hi,

In your code, why are you first looping over all the forms and doing this comparison:

If SBO_Application.Forms.Item(x).Type = "134"

Secondly, you are checking whether the menu item already exists..

Is this approach better, or the one suggested by Ankit where he is removing the menu, after the Right Click?

Thanks.

rajesh_khater
Active Participant
0 Kudos

ok I think I got it. Since the event does not have any property to check the form type, and the Form UID keeps changing every time, so you are checking whether the required form is currently open or not.

But cant you simply check the Form Type for the Active Form, instead of looping over all forms?

rajesh_khater
Active Participant
0 Kudos

For the sake of completeness, I think I need to compare the Form Type for the ActiveForm. Otherwise if say Business Partner form is open but not the Active Form, then the right click menu will come in whichever active form, which is wrong.

So I have added the condition to check :

C# code:

if (activeForm.Type == 134)

Answers (2)

Answers (2)

rajesh_khater
Active Participant
0 Kudos

Hi Srinivas and Ankit,

I have posted a separate but related question here.

Please try to answer.

Thanks.

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

There is a sample in SDK Help Center for this:

Private Sub SBO_Application_RightClickEvent(ByRef eventInfo As SAPbouiCOM.ContextMenuInfo, ByRef BubbleEvent As Boolean) Handles SBO_Application.RightClickEvent
    If eventInfo.FormUID = "RightClk" Then
        If (eventInfo.BeforeAction = True) Then
            Dim oMenuItem As SAPbouiCOM.MenuItem
            Dim oMenus As SAPbouiCOM.Menus

            Try
                Dim oCreationPackage As SAPbouiCOM.MenuCreationParams
                oCreationPackage = SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_MenuCreationParams)

                oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_STRING
                oCreationPackage.UniqueID = "OnlyOnRC"
                oCreationPackage.String = "Only On Right Click"
                oCreationPackage.Enabled = True

                oMenuItem = SBO_Application.Menus.Item("1280") 'Data'
                oMenus = oMenuItem.SubMenus
                oMenus.AddEx(oCreationPackage)
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        Else
            Dim oMenuItem As SAPbouiCOM.MenuItem
            Dim oMenus As SAPbouiCOM.Menus

            Try
                SBO_Application.Menus.RemoveEx("OnlyOnRC")
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End If
    End If
End Sub




Hope it helps.

Thanks & Regards

Ankit Chauhan

rajesh_khater
Active Participant
0 Kudos

Hi Ankit,

In your code, I have not understood 2 lines:

If eventInfo.FormUID = "RightClk"


- Here I am supposed to give FormUID for the Form for which I want to modify the right click menu, am I right?


oMenuItem = SBO_Application.Menus.Item("1280")


- What does 1280 indicate here?


Thanks.

rajesh_khater
Active Participant
0 Kudos

Ankit,

I think the comparison with FormUID is wrong, as FormUID will keep changing every time. Pls correct me if I am wrong.

Thanks.

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Rajesh,

1280 is the Menu Id of Data Menubar.

Data is available Next to File->Edit->View.

And yes you can check the FormType. This was just for sample.

Hope it helps.

Thanks & Regrads

Ankit Chauhan