cancel
Showing results for 
Search instead for 
Did you mean: 

how to close AddOn form after adding a record

former_member369006
Participant
0 Kudos

Hello

I am implementing a AddOn that has its own form operating on User-Defined-Object.

Please tell me how can I force form to close after record is added/inserted.

I was trying to override FORM_DATA_ADD Event (after event) but neither form.Close() nor form.Items.Item("2").Click() (simulation of cancel buton) didn't work for me or caused unexpected close of SAP B1

Regards,

Pawel

Accepted Solutions (1)

Accepted Solutions (1)

pedro_magueija
Active Contributor

Hi Pawel,

Form_Data_Add (after) event occurs before the Item_Pressed (after) event. B1 needs the form that initially triggered the Item_Pressed open (perhaps this is why you get the errors).

You could catch the Item_Pressed (after) event on the add button (id = 1) and the use the simple form.Close();

By that time no other (native) events should be triggered and the form.Close() should be successful.


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

Answers (3)

Answers (3)

Former Member

Hi Pawel,

you can't close the form in SBO_Application_FormDataEvent but you can tray this code:

'Declare public boolean variable

public variableAdd as boolean = False

'in SBO_Application_FormDataEvent if add is in actionSuccess set variable at true

  If BusinessObjectInfo.BeforeAction = False Then

     if BusinessObjectInfo.EventType = SAPbouiCOM.BoEventTypes.et_FORM_DATA_ADD Then

          If BusinessObjectInfo.ActionSuccess Then

               variableAdd=true

          end if

        end if

    end if

'In SBO_Application_ItemEvent after press on button "1" close form

If pVal.BeforeAction = False Then

  if pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then

         if If pVal.ItemUID = "1" Then

             if  variableAdd=true Then

                variableAdd=false

               form.Items.Item("2").Click()

               end if

         end if

  End if

else

'set public variable to false

if pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED Then

         if If pVal.ItemUID = "1" Then

             if  variableAdd=true Then

                variableAdd=false

             end if

         end if

  End if

end if

,Regards Alessandro

former_member369006
Participant
0 Kudos

Thank you very much for your help.

The solution suggested both by Alessandro and Pedro works for me,

Regards.

Former Member
0 Kudos

Hi Pawel,

Easiest is to change the Form.Mode and to set it to Ok before B1 changes it: by doing so, it will detect that the form was already in Ok mode and closes the form.

Regards,

Eric