Wednesday, July 18, 2012

To save or not to save?

In some cases it should not be possible to save orders with errors, but when you hit the ‘Back’ arrow you receive the data loss popup whether or not you want to save the changes.
When the user chooses ‘Yes’ the order with errors will be saved.
To prevent the changes to be saved (when the order contains errors) we can enhance the main window.

First of all we need to enhance the MainWindow so implementation Class ZL_BT115QH_MAINWINDOW_IMPL will be created. In this class you need to redefine some methods.

In the example our starting point is when the user chooses ‘Yes’ in the data loss popup. For this we need to redefine method ‘IF_BSP_WD_EVENT_HANDLER~HANDLE_EVENT.

In this method we copied the code from the original method and added the variable lv_number_of _errors. Since there is already a reference to the message service class we can get the number of errors.
If there are  errors we want to show an error popup, for that we created method EH_ONERROR_POPUP.

In this method the error popup gets created, for this you need to create a class attribute.

After the popup is created we register the on close event to our custom event ‘ERROR_POPUP_CLOSED’ so when the popup gets closed we can call a method to handle the answer. The error_popup->open( ) statement then opens the popup.

The popup opens and the user has the option to select ‘Yes’ or ‘No’.

To recognize our custom event (ERROR_POPUP_CLOSED) you have to redefine method DO_HANDLE_EVENT and call the logic needed by this event.

If the user decides to address the errors the ‘Yes’ button gets clicked and the user returns to the order. If the user don’t want to make any changes ‘No’ will be clicked and will be directed away from the order.

Contributed by Aart Troost | Acorel B.V.