Skip to Content
0

How to work with SAP B1 buttons in SDK?

Oct 18, 2017 at 10:27 AM

119

avatar image

Hi all,

I tried to take event from menu buttons successfully like this

    Private Sub SBO_Application_MenuEvent(ByRef pVal As SAPbouiCOM.MenuEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.MenuEvent
        If SBO_Application.Forms.ActiveForm.TypeEx.Equals("1250000100") Then
            If pVal.BeforeAction = True Then
                SBO_Application.MessageBox("Button pressed " & vbNewLine & "Hello World!")
            End If
        End If

How can I take event from form buttons like Add and Update of the system form (A/R Invoice)?

This means, If I click Add or Update button and execute my addition codes

Please anyone can help me

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
ANKIT CHAUHAN
Oct 18, 2017 at 11:09 AM
1

Hi,

You can use either Item Event for your purpose or can use Data Event:

Data Event:

SBO_Application.FormDataEvent += new SAPbouiCOM._IApplicationEvents_FormDataEventEventHandler(Handle_SBO_DataEvent);

public override void Handle_SBO_DataEvent(ref BusinessObjectInfo BusinessObjectInfo, out bool BubbleEvent)
{
    BubbleEvent = true;
    if (BusinessObjectInfo.BeforeAction == false && BusinessObjectInfo.EventType == BoEventTypes.et_FORM_DATA_UPDATE && BusinessObjectInfo.FormTypeEx == "134")
    {
        // Write your logic here.
    }
}

Item Event:

if (pVal.FormType == 141 && pVal.ActionSuccess == true && pVal.EventType == BoEventTypes.et_ITEM_PRESSED && pVal.ItemUID == "1" && pVal.FormMode == 3)
 {
    // Write your logic here.
 }

There might have been too many threads on this type of issue. Please search it. Also refer to SDK Help Center for the same.

Hope it helps!

Kind regards,

ANKIT CHAUHAN

SAP SME Support

Show 9 Share
10 |10000 characters needed characters left characters exceeded

Hi Ankit,

I tried to use

        If pVal.FormType = 141 AndAlso pVal.ActionSuccess = True AndAlso pVal.EventType = BoEventTypes.et_ITEM_PRESSED AndAlso pVal.ItemUID = "1" AndAlso pVal.FormMode = 3 Then
            SBO_Application.MessageBox("Button pressed " & vbNewLine & "Hello World!")
        End If

But I'm getting one error from BoEventTypes the error says 'BoEventTypes' is not declared. It may be inaccessible due to its protection level.

How can I declare BoEventTypes in bellow private sub or other private sub?

Private Sub SBO_Application_MenuEvent(ByRef pVal As SAPbouiCOM.MenuEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.MenuEvent

I think I forgot a little thing

0

Hi,

You should use it under Item Event rather Menu Event.

Kind regards,

ANKIT CHAUHAN

SAP SME Support

0

Thank you Ankit, it works fine. another one question.

If I click Add button it adds data and then execute my codes,

So how can I execute my code before and then add data after?

Is it possible?

0

Hi Rurangwa,

Yes,obsoletely possible

1.After Successfully add data

if (BusinessObjectInfo.FormTypeEx == "134" && BusinessObjectInfo.Type == "2" BusinessObjectInfo.ActionSuccess == true && eventType == "et_FORM_DATA_UPDATE")
{
//Write your logic here
}

2.Before add data.

if (BusinessObjectInfo.FormTypeEx == "134" && BusinessObjectInfo.Type == "2" BusinessObjectInfo.ActionSuccess == false && eventType == "et_FORM_DATA_UPDATE")
{
//Write your logic here
}

Thanks,

Chenna.

0

Hi Chenna,

Thank you, but can you please help me to convert the above codes in visual basic

I tried to convert them by using http://converter.telerik.com/ but it gives me error while converting

Help me please

0

Hi Rurangwa,

Please find the below VB code

Public Sub SBO_Application_FormDataEvent(ByRef BusinessObjectInfo As SAPbouiCOM.BusinessObjectInfo, ByRef BubbleEvent As Boolean)
BubbleEvent = True
Try

If BusinessObjectInfo.FormTypeEx = "134" AndAlso BusinessObjectInfo.Type = "2" AndAlso BusinessObjectInfo.ActionSuccess = True AndAlso BusinessObjectInfo.EventType = SAPbouiCOM.BoEventTypes.et_FORM_DATA_UPDATE Then
//Write your logic here
End If
If BusinessObjectInfo.FormTypeEx = "134" AndAlso BusinessObjectInfo.Type = "2" AndAlso BusinessObjectInfo.ActionSuccess = FALSE AndAlso BusinessObjectInfo.EventType = SAPbouiCOM.BoEventTypes.et_FORM_DATA_UPDATE Then
//Write your logic here
End If

Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End Sub

Hope it helps you.

Thanks,

Chenna.

0

Hi Chenna,

Thank you, I tried to paste your codes there they have no error but they do not execute anything.

I tried to add only SBO_Application.MessageBox("Hello World") but I add BP and it is added successfully without messagebox Hello world

    Public Sub SBO_Application_FormDataEvent(ByRef BusinessObjectInfo As SAPbouiCOM.BusinessObjectInfo, ByRef BubbleEvent As Boolean)
        BubbleEvent = True
        Try
            If BusinessObjectInfo.FormTypeEx = "134" AndAlso BusinessObjectInfo.Type = "2" AndAlso BusinessObjectInfo.ActionSuccess = True AndAlso BusinessObjectInfo.EventType = SAPbouiCOM.BoEventTypes.et_FORM_DATA_UPDATE Then
                SBO_Application.MessageBox("Hello World")
            End If
            If BusinessObjectInfo.FormTypeEx = "134" AndAlso BusinessObjectInfo.Type = "2" AndAlso BusinessObjectInfo.ActionSuccess = False AndAlso BusinessObjectInfo.EventType = SAPbouiCOM.BoEventTypes.et_FORM_DATA_UPDATE Then
                SBO_Application.MessageBox("Hello World")
            End If
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try
    End Sub

I pasted above codes inside the class Public Class SystemForm but there is no message Hello world

If it's possible you can test it by using for example sample in C:\Program Files (x86)\SAP\SAP Business One SDK\Samples\COM UI\VB.NET\11.SystemFormManipulation.

Help me please

0

Hi Rurangwa,

if you want to add BP data, you have to change code.

BusinessObjectInfo.EventType = SAPbouiCOM.BoEventTypes.et_FORM_DATA_ADD

Thanks,

Chenna.

0

Thank you so much Chenna.

0