Skip to Content

Summary:

How to give data loss popup when navigating from custom component to other components or documents using Quick links or Navigation bar links when used in WEBUI

This document will be helpful when we are using custom component in WEBUI as standalone component

Step1:In custom component mainwindow IMPL class we have add one interface IF_BSP_WD_EVENT_HANDLER under interfacedata1.PNG

Step2:We have to create one method for data loss poupup and register it for data loss in methods

data5.PNG

After this keep cursor on the method and click Detail View (highlighted) and give below details in the screenshot

data6.PNG

Here we have to code for triggering the data loss popup. Put logic whether data entered or modified in the component and raise popup

IF gv_update EQ abap_true.

    data_loss_handler->set_save_handler( me ).
    data_loss_handler->set_revert_handler( me ).
    data_loss_handler->set_cancel_handler( me ).

    data_loss_handler->trigger_data_loss_handling( ).
  ENDIF.

Step3:Activate Data loss popup Event Handler

We have to activate data loss popup event in method DO_VIEW_INIT_ON_ACTIVATION

data4.PNG

Here we have to put code to activate data loss popup event

CALL METHOD SUPER->DO_VIEW_INIT_ON_ACTIVATION.

* Enable Data Loss Popup

  SET HANDLER on_before_wa_content_change ACTIVATION abap_true.

Step4:Deactivating data loss popup event handler

Here in method DO_CLEANUP_CONTEXT

data7.PNG

Here put code to deactivate event handler

CALL METHOD super->do_cleanup_context
    .

  SET HANDLER on_before_wa_content_change ACTIVATION abap_false.

Step5:Add attributes

Under Attributes add two attributes DATA_LOSS_TRIGGER_VIEW and DATA_LOSS_TRIGGER_EVENT

data3.PNG

Step6:In WIndow IMPL class we will have method IF_BSP_WD_EVENT_HANDLER~HANDLE_EVENT under methods

data2.PNG

Here we have to code for data loss popup buttons. Here you will have the user option whether save or cancel

When user clicked yes you have to put logic to update your custom table with the details entered in custom component view

CASE iv_event_name.
    WHEN if_bsp_wd_data_loss_handler=>save_event.
      rv_success = abap_true.

      lr_core ?= cl_crm_bol_core=>get_instance( ).
      lr_msg_srv ?= lr_core->get_global_message_cont( ).
      lr_coco ?= me->comp_controller.
      lr_col ?= lr_coco->typed_context->data->collection_wrapper.

      lr_entity ?= lr_col->get_first( ).

      WHILE lr_entity IS BOUND.

        CALL METHOD lr_entity->get_properties
          IMPORTING
            es_attributes = lwa_data.

          APPEND lwa_data TO li_data.
          CLEAR lwa_emp_org.
      
        lr_entity ?= lr_col->get_next( ).

      ENDWHILE.

      MODIFY Ztable FROM TABLE li_data.
      IF sy-subrc = 0.
        COMMIT WORK.
      ENDIF.
      CLEAR:gv_update.
      lr_msg_srv->add_message( iv_msg_id = ‘ZCRM_MESS’ iv_msg_type = ‘S’ iv_msg_number = ‘031’ iv_show_only_once = ‘X’).
      CLEAR me->data_loss_trigger_view.
      CLEAR me->data_loss_trigger_event.
    WHEN if_bsp_wd_data_loss_handler=>revert_event.
      rv_success = abap_true.
      CLEAR me->data_loss_trigger_view.
      CLEAR me->data_loss_trigger_event.
    WHEN if_bsp_wd_data_loss_handler=>cancel_event.
      rv_success = abap_false.
**      RETURN.
      CLEAR me->data_loss_trigger_view.
      CLEAR me->data_loss_trigger_event.
    WHEN OTHERS.

  ENDCASE.

This Popup will be called when user navigates out of component without saving the data.

Regards,

Deepika.

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Anil Supraj

    Hi Deepika,

    Will this trigger if I try to close web ui window. Will I get a data loss popup here as well.

    also I have below piece of code already existing in methods mentioned in the blog.

      lr_access = cl_crm_uiu_bt_channel_asp_fac=>get_instance( ).

      lv_data_loss_enabled = lr_access->if_crm_uiu_channel_aspects~is_data_loss_enabled( ).

    * Enable Data Loss Popup

      super->do_cleanup_context( ).

    * disable dataloss popup (if active before)

      IF lv_data_loss_enabled = abap_true.

        SET HANDLER on_before_wa_content_change ACTIVATION abap_false.

      ENDIF.

    Disable data loss condition is failing for me. Is there any such configuration where this flag is enabled/disabled ?

    Thanks,

    Anil

    (0) 

Leave a Reply