Wednesday, November 5, 2014

Implement an event handler in a CRM webclient search view

As a CRM webclient developer it is very common to implement search views. A user would be able to specify his search criteria and search for relevant objects.
What if you would want to change the behaviour of the screen for instance based on an action in the screen? You might think of a scenario where you want to influence the appearance of the search view based one of the search fields. 
Let’s assume you have a search view where you can specify a centain item type, which is displayed as a dropdown listbox.


Based on the value given, you would like:
  • Other search parameters to appear or disappear
  • Other dropdown listboxes to change their possible values
  • Inform the user with a certain message
In a normal overview page, you could define the event in the P-getter. Unfortunately, the P-getter method in a search view does not allow you to set an event for the dropdown listbox, so you are not able to do such things. But there is an alternative.

Create an event handler for the search parameter

In the controller class of the searchquery view, method GET_DQUERY_DEFINITIONS is used to retrieve search field information. This method allows you to change the server event for search fields. Redefine this method and change the server event setting for the search parameter.
METHOD get_dquery_definitions.
FIELD-SYMBOLS:
     <lfs_field_info> TYPE crms_thtmlb_search_field_info.
 
CALL METHOD super->get_dquery_definitions
    RECEIVING
    rt_result = rt_result.
 
READ TABLE rt_result ASSIGNING <lfs_field_info> WITH KEY field = 'ITM_TYPE'.
IF sy-subrc = 0.
     <lfs_field_info>-server_event = 'ITM_TYPE_CHANGED'. "Just used for roundtrip!
ENDIF.
 
ENDMETHOD.
Note that we are here working on the search field definition. This is not the actual raising of the event, this will be done by the framework automatically when a value is set from the dropdown.

You could then either create the event handler to implement your specific logic, or just use a dummy event, simply to trigger a roundtrip.

1 comment: