SAP CRM — WEB IC Search view and Result view Navigation

Let us see how we can navigate between search and result view.

To learn how to create search and result view Click Here.

Once you know created the search and result view now we need to create a search button. I added the following code in the srviewset.htm.

<%@page language=”abap” %>
<%@extension name=”htmlb” prefix=”htmlb” %>
<%@extension name=”xhtmlb” prefix=”xhtmlb” %>
<%@extension name=”thtmlb” prefix=”thtmlb” %>
<%@extension name=”crm_bsp_ic” prefix=”crmic” %>
<%@extension name=”bsp” prefix=”bsp” %>
<%@extension name=”chtmlb” prefix=”chtmlb” %>
<%
***  Determine if search is to be collapsed
DATA lv_show_fields TYPE string.
”  lv_show_fields = ‘X’.
”  IF lv_show_fields EQ abap_false.
lv_show_fields = ‘true’.
”  ELSE.
” lv_show_fields = ‘false’.
”  ENDIF.
%>
<chtmlb:pageType type=“SEARCH” >
<thtmlb:searchFrame showSearchFields   = “<%= lv_show_fields %>”
onShowSearchFields = “TOGGLESEARCHDISPLAY”
onHideSearchFields = “TOGGLESEARCHDISPLAY” >
<thtmlb:searchCriteriaFrame>
<%
”  IF lv_show_fields EQ abap_false.
%>
<thtmlb:searchArea>
<thtmlb:searchTagArea>
<bsp:call comp_id = “<%= controller->GET_VIEWAREA_CONTENT_ID( ‘SV’ ) %>”
url     = “<%= controller->GET_VIEWAREA_CONTENT_URL( ‘SV’ ) %>” />
</thtmlb:searchTagArea>
<thtmlb:searchButtonsArea>
<thtmlb:button id“SearchBtn”
design  = “EMPHASIZED”
onClick“SEARCH”
text“Search”
tooltip = “Search” />
<thtmlb:button id“Clearbtn”
onClick“CLEAR”
text“Clear”
tooltip = “Clear” />
</thtmlb:searchButtonsArea>
</thtmlb:searchArea>
<%
“Endif.
%>
</thtmlb:searchCriteriaFrame>
<thtmlb:searchResultFrame>
<bsp:call comp_id = “<%= controller->GET_VIEWAREA_CONTENT_ID( ‘RV’ ) %>”
url     = “<%= controller->GET_VIEWAREA_CONTENT_URL( ‘RV’ ) %>” />
</thtmlb:searchResultFrame>
</thtmlb:searchFrame>
</chtmlb:pageType>

With the above html I added the search button on the viewset. The button code is placed in between the view.

See the following screen shot for the button.

srv_nvg_01

Now we have the button. We need to add the search event on the viewset as well as in the search view. See the following screen shots for event creation.

srv_nvg_02

srv_nvg_03

srv_nvg_04

Add the following code in the searchadv view on the event handler.

METHOD eh_onsearch.
DATA: query_service TYPE REF TO cl_crm_bol_dquery_service.
DATA: result TYPE REF TO if_bol_bo_col.

query_service ?= me->typed_context->TestSearch->collection_wrapper->get_current( ).
result = query_service->get_query_result( ).

me->typed_context->testresult->collection_wrapper->clear( ).

me->typed_context->testresult->set_collection( result ).
ENDMETHOD.

Once the code is added  your component should trigger when ever you click on the search and get the result and show in the result view.

Now we need to add some code in the DO_HANDLE_EVENT method of the implementation class of srviewset view. In that method you are asking the event to be raised for the searchadv view, so that the code in the advsearch will be called. You can directly put the code in the viewset so you no need to do the above.

Add the following code in the DO_HANDLE_EVENT method of the ZL_ZSRCMP1_SRVIEWSET_IMPL.

METHOD do_handle_event.
* Eventhandler dispatching
DATA: lv_viewname TYPE string,
lr_viewctrl TYPE REF TO cl_bsp_wd_view_controller.
CASE htmlb_event_ex->event_server_name.

*     Added by wizard
**      WHEN ‘SEARCH’.                                        “#EC NOTEXT
*        EH_ONSEARCH( htmlb_event    = htmlb_event
*                    htmlb_event_ex = htmlb_event_ex ).

WHEN OTHERS.
lv_viewname = me->get_viewarea_content( ‘SV’ ).       “#EC NOTEXT
IF lv_viewname IS NOT INITIAL.
lr_viewctrl = me->get_subcontroller_by_viewname( lv_viewname ).
IF lr_viewctrl IS BOUND.
TRY.
CALL METHOD lr_viewctrl->(‘DO_HANDLE_EVENT’)
EXPORTING
eventevent
htmlb_event     = htmlb_event
htmlb_event_ex  = htmlb_event_ex
global_messages = global_messages
RECEIVING
global_event    = global_event.

CATCH cx_sy_dyn_call_error.
RETURN.
ENDTRY.
ENDIF.
ENDIF.
ENDCASE.

ENDMETHOD.

Now your code is ready to execute had show the results. See the following screen shot.

srv_nvg_05

Now you get the result in the result view. Let me know if you have any questions.

9 thoughts on “SAP CRM — WEB IC Search view and Result view Navigation

  1. Hi,

    I created my own search and result veiw and bind it with custom controller. When i search it for first time, I can see the results in result view but when i do the search again with some other parameter then i get the correct number of records but all blank records.
    Could you please give me some direction how can i fix this?

    Regards,

    Kamesh

  2. Hi

    Thank you very much for the post. It was very useful and has indeed answered many questions that I previously had relating to the data transfer in the table views.

    Thanks
    Raj

  3. Hi,
    nice blog! I ran into some minor problems but now it is up and running. Albeit the next step missing now is the link from the search result to the view that shows the data. Best of all including data manipulation a.k.a. edit mode and the possiblity to add new entries via the Web Client. One or two blog entries more with that in mind would be awesome!

    Cheers,
    Hendrik

  4. Hi,

    Thanx for an excellent blog, very helpful indeed. Everything is working fine except i m running into a minor issue. When coding method eh_onsearch in searchadv view,

    me->typed_context->testresult->collection_wrapper->clear( ).

    me->typed_context->testresult->set_collection( result ).

    my testresult is not getting recognised, also we have not added the testresult in the searchadv view, hence getting he error. Am i missing something. We added testresult in the resultview instead and we are referring to it here.

    Also, i would like to know that why we had to create search event twice, once for the searchadv view
    and one for the viewset.

    Waiting for your feedback on this.

    ssalaria.sap@gmail.com

  5. The viewset event is just to caputer and pass the control to the searchadv where the data is filled for the result view.

    please check the BOL logic and see if your data is populated.

  6. Very nice blog, and very usefull entries.
    I’ve come to a problem after creatin the search succesfully…
    Ive tried to link the custom search to the main menu and Im getting the next error…
    do you know what is wrong? I can test my search through the BSP_WD_CMPWB correctly

    “Business Server Page (BSP) error

    What happened?
    Calling the BSP page was terminated due to an error.

    SAP Note

    The following error text was processed in the system:
    BSP exception: Object srviewset.htm in URL sap/zpos_facturas3/srviewset.htm is a view; start the corresponding controller ”

    thanks in advance!
    David.

  7. Hi,

    The post is very good.
    i am facing a problem, the search query doesn’t work, get the same result every time( entire table entries) for different queries, seems some problem with the BOL query,

    METHOD if_genil_appl_intlay~get_dynamic_query_result.
    DATA: lr_object TYPE REF TO if_genil_cont_root_object,
    lt_result TYPE TABLE OF zes_test_tbl,
    l_result TYPE zes_test_tbl.

    SELECT * FROM ztest_test_tbl INTO TABLE lt_result.

    LOOP AT lt_result INTO l_result.
    lr_object = iv_root_list->add_object( iv_object_name = ‘TestRoot’
    is_object_key = l_result-name ).
    lr_object->set_query_root( abap_true ).
    ENDLOOP.
    ENDMETHOD.

    can you please help

    Regards,
    SK

Leave a comment