1. Add Reason field to the Search View Add a new entry to the BOL structure CRMST_QUERY_ACT_BTILusing the 'Append Structure' option, as shown below. This will add our custom field Reason to the search parameter list. Then add it to the Account Search view configuration
2.To make the reason filed a Drop Down, create a new method GET_V_ZREASON in the class ZL_BT126S_A_APPTSQ_IMPL.
method GET_V_ZREASON. data: lt_ddlb type bsp_wd_dropdown_table, ls_ddlb_options type crms_thtmlb_search_ddlb_nvp. DATA:IV_SEPARATOR TYPE CHAR1 value '*'. field-symbols: <ls_ddlb> type bsp_wd_dropdown_line. FIELD-SYMBOLS: <osset_wrk1> TYPE crmt_srv_osset_wrk1, <code> TYPE com_code_f4. DATA: ls_srv_osset_wrk TYPE crmt_srv_osset_wrk, lt_code_tab TYPE STANDARD TABLE OF com_code_f4, ls_dropdown_line TYPE bsp_wd_dropdown_line, lt_dropdown_tab TYPE bsp_wd_dropdown_table. data : lr_query_service type ref to cl_crm_bol_dquery_service. data : lr_col2 type ref to if_bol_bo_col. data : lr_property type ref to if_bol_bo_property_access. data: ls_selection type genilt_selection_parameter. data: proc_type type string. data: subject_pro type crmt_subject_profile value 'ZACT00001'. **** Get possible values * call method cl_crm_uiu_cust_get=>get_values_for_field * exporting * iv_fieldname = '' * receiving * rt_value = lt_ddlb * exceptions * others = 4. *lt_ddlb = cl_crm_uiu_bt_tools=>get_strcmp_ddlb( iv_structure = 'CRMD_ACTIVITY_H' * lr_query_service ?= me->typed_context->btqact->collection_wrapper->get_current( ). lr_col2 ?= lr_query_service->get_selection_params( ). lr_property ?= lr_col2->get_first( ). WHILE lr_property is bound. lr_property->get_properties( IMPORTING es_attributes = ls_selection ). if ls_selection-attr_name = 'PROCESS_TYPE'. proc_type = ls_selection-low. * if ls_selection-attr_name = 'CATEGORY'. * cat = ls_selection-low. endif. lr_property ?= lr_col2->get_next( ). ENDWHILE. if strlen( proc_type ) > 0. SELECT SINGLE subject_profile FROM crmc_activity_h INTO subject_pro WHERE process_type = proc_type. endif. CALL FUNCTION 'CRM_SUBJECT_PROF_CODES_PROVIDE' EXPORTING i_subject_profile = subject_pro TABLES e_code_tab = lt_code_tab EXCEPTIONS OTHERS = 0. LOOP AT lt_code_tab ASSIGNING <code>. CLEAR ls_dropdown_line. CONCATENATE <code>-katalogart IV_SEPARATOR <code>-codegruppe IV_SEPARATOR <code>-code INTO ls_dropdown_line-key. * ls_dropdown_line-key = <code>-text. ls_dropdown_line-value = <code>-text. APPEND ls_dropdown_line TO lt_dropdown_tab. ENDLOOP. lt_ddlb = lt_dropdown_tab. *** Add empty line append initial line to lt_ddlb. *** Prepare to return values loop at lt_ddlb assigning <ls_ddlb>. ls_ddlb_options-key = <ls_ddlb>-key. ls_ddlb_options-value = <ls_ddlb>-value. insert ls_ddlb_options into table cs_result-ddlb_options. endloop. endmethod.
This method includes the logic to default the Reason filed drop down values if no Process Type is selected. If a process type is selected the Reason drop down values are populated accordingly. According to the Process Type selected, retrieve the Subject Profile and then using the function module 'CRM_SUBJECT_PROF_CODES_PROVIDE' get the drop down values.
3. To trigger a Server Round trip when a drop down value is selected, enhance the method GET_DQUERY_DEFINITIONS, of the implementation class ZL_BT126S_A_APPTSQ_IMPL. Include the highlighted line of code as shown below.
<rt_result>-server_event = 'DDLB_CLICK'.
3.Add Reason field to the Result View Enhance the view BT126S_APPT/ApptSR of the component BT126S_APPT. Create a new attribute 'ZREASON' to the context node BTQRACT using the wizard as shown below.
Generate the Getter and Setter method by right clicking on the attribute.
Now implement the GET_ZREASON method as shown below.
method GET_ZREASON. DATA: current TYPE REF TO if_bol_bo_property_access. DATA: dref TYPE REF TO data. data: lr_entity type ref to cl_crm_bol_entity. value = 'BTQAct not bound'."#EC NOTEXT if iterator is bound. current = iterator->get_current( ). else. current = collection_wrapper->get_current( ). endif. *WHILE lr_entity IS BOUND. lr_entity ?= current. lr_entity ?= lr_entity->get_related_entity( iv_relation_name = 'BTADVSAct' ). if lr_entity IS BOUND. lr_entity ?= lr_entity->get_related_entity( iv_relation_name = 'BTOrderHeader' ). if lr_entity IS BOUND. lr_entity ?= lr_entity->get_related_entity( iv_relation_name = 'BTHeaderBOSSet' ). if lr_entity IS BOUND. lr_entity ?= lr_entity->get_related_entity( iv_relation_name = 'BTSubjectSet_F' ). if lr_entity IS BOUND. lr_entity ?= lr_entity->get_related_entity( iv_relation_name = 'BTSubjectAll' ). * if lr_entity IS BOUND. * lr_property ?= lr_entity. * reason = lr_property->get_property_as_string( 'CODETEXT' ). endif. endif. endif. endif. current ?= lr_entity. TRY. TRY. dref = current->get_property( 'CODETEXT' ). "#EC NOTEXT CATCH cx_crm_cic_parameter_error. ENDTRY. CATCH cx_sy_ref_is_initial cx_sy_move_cast_error cx_crm_genil_model_error. RETURN. ENDTRY. IF dref IS NOT BOUND. value = 'BTQAct/ZREASON not bound'."#EC NOTEXT RETURN. ENDIF. TRY. value = if_bsp_model_util~convert_to_string( data_ref = dref attribute_path = attribute_path ). CATCH cx_bsp_conv_illegal_ref. FIELD-SYMBOLS: <l_data> type DATA. assign dref->* to <l_data>. * please implement here some BO specific handler coding * conversion of currency/quantity field failed caused by missing * unit relation * Coding sample: * provide currency, decimals, and reference type * value = cl_bsp_utility=>make_string( * value = <l_data> * reference_value = c_currency * num_decimals = decimals * reference_type = reference_type * ). CONCATENATE <l_data> 'CURR/QUANT CONV FAILED' INTO value SEPARATED BY space. "#EC NOTEXT CATCH cx_root. value = 'CONVERSION FAILED'. "#EC NOTEXT ENDTRY. endmethod.
4. Implement search using Reason field with the BADI Go to se18 BADi : CRM_BADI_RF_Q1O_SEARCH
Create an implementation for the BADI
Add the filter value . This value would be the context node for which we need to enhance the search. BTQACT = OBJ_IL
Implement the IF_CRM_RF_Q1O_SEARCH~SEARCH method of the BADi for the search logic.
method IF_CRM_RF_Q1O_SEARCH~SEARCH. * **Reasoncode in Activity Search ******** DATA: lt_selection_parameters TYPE genilt_selection_parameter_tab. DATA: ls_selection_parameters LIKE LINE OF lt_selection_parameters. DATA: lt_return TYPE bapiret2_ta. DATA: lt_multivalues type crmt_bsp_search_multi_val_tab, ls_multivalues type LINE OF crmt_bsp_search_multi_val_tab, lt_guidlist TYPE crmt_bsp_objectkey_tab, lv_qualauto type CRMT_BSP_LOW, lv_objid type CRMT_BSP_LOW, LV_WEBCEID TYPE CRMT_BSP_LOW, lv_auto type boolean , lv_web type boolean , lv_reason type boolean, lv_object type boolean, lv_count type i, lv_lines type i, lv_help_par1 TYPE string, lv_par1 LIKE sy-msgv1, ls_return TYPE LINE OF bapiret2_t, lv_num type i, lv_cgrp type string, lv_statreason type char20. DATA : lt_guid type crmt_object_guid_tab, ls_guid type CRMT_OBJECT_GUID, lt_guids type crmt_object_guid_tab, lt_guid1 TYPE crmt_object_guid_tab, lt_guid2 TYPE crmt_object_guid_tab. **** DATA: lt_service_os TYPE crmt_srv_osset_wrkt. DATA: ls_service_os TYPE crmt_srv_osset_wrk. DATA: ls_ossubject TYPE crmt_srv_subject_wrk. DATA: ls_osset TYPE crmt_srv_osset_wrk1. DATA:IV_SEPARATOR TYPE CHAR1 value '*'. DATA: str1 TYPE string, str2 TYPE string, str3 TYPE string, itab TYPE TABLE OF string, text TYPE string. ls_selection_parameters-sign = 'I'. ls_selection_parameters-option = 'EQ'. FIELD-SYMBOLS: <ls_search_tab> LIKE LINE OF it_search_tab. DATA ls_rfw_multivalues TYPE crmt_report_search_multi_val. LOOP AT it_search_tab ASSIGNING <ls_search_tab>. ls_selection_parameters-attr_name = <ls_search_tab>-name. ls_selection_parameters-low = <ls_search_tab>-value. INSERT ls_selection_parameters INTO TABLE lt_selection_parameters. ENDLOOP. FIELD-SYMBOLS: <ls_multivalues> LIKE LINE OF it_multivalues. LOOP AT it_multivalues ASSIGNING <ls_multivalues>. ls_selection_parameters-attr_name = <ls_multivalues>-fieldname. if <ls_multivalues>-fieldname EQ 'ZREASON'. lv_reason = 'X'. else. ls_multivalues = <ls_multivalues>. APPEND ls_multivalues to lt_multivalues. if <ls_multivalues>-fieldname EQ 'OBJECT_ID'. lv_object = 'X'. endif. clear lv_auto. ENDIF. FIELD-SYMBOLS: <ls_searchvalues> LIKE LINE OF <ls_multivalues>-searchvalues. LOOP AT <ls_multivalues>-searchvalues ASSIGNING <ls_searchvalues>. if lv_reason = 'X'. lv_statreason = <ls_searchvalues>-low. clear lv_reason. ENDIF . MOVE-CORRESPONDING <ls_searchvalues> TO ls_selection_parameters. INSERT ls_selection_parameters INTO TABLE lt_selection_parameters. ENDLOOP. ENDLOOP. **Check if the selection Criteria has a value in Reason Code if lv_statreason is INITIAL. CALL FUNCTION 'CRM_BSP_OIC_1O_SEARCH_FROM_RF' EXPORTING IT_SEARCH_TAB = it_search_tab IV_NUMBER = iv_number IT_MULTIVALUES = lt_multivalues iv_extern_call = 'X' iv_select_for_headerlevel = 'X' iv_call_authority_badi = 'X' IMPORTING ET_GUIDLIST = lt_guidlist et_return = et_return. et_guidlist = lt_guidlist. else. DESCRIBE TABLE lt_multivalues LINES lv_count. if lv_count >= 1 or lv_objid is not initial. CALL FUNCTION 'CRM_BSP_OIC_1O_SEARCH_FROM_RF' EXPORTING IT_SEARCH_TAB = it_search_tab IT_MULTIVALUES = lt_multivalues iv_extern_call = 'X' iv_select_for_headerlevel = 'X' iv_call_authority_badi = 'X' IMPORTING ET_GUIDLIST = lt_guidlist et_return = et_return. lt_guid[] = lt_guidlist. if lv_statreason is NOT INITIAL and lt_guid is not INITIAL. ********** split lv_statreason AT iv_separator INTO: str1 str2 str3. * select CRMD_ORDERADM_H~guid from CRMD_ORDERADM_H INNER JOIN crmd_link as link on link~guid_hi = CRMD_ORDERADM_H~guid INNER JOIN CRMD_SRV_OSSET as set on set~guid_set = link~guid_set INNER JOIN crmd_srv_subject as subject on subject~guid_ref = set~guid into TABLE lt_guids FOR ALL ENTRIES IN lt_guid where CRMD_ORDERADM_H~guid = lt_guid-table_line and link~objtype_set = '29' and subject~KATALOGART = str1 and subject~CODEGRUPPE = str2 and subject~code = str3. lt_guid[] = lt_guids[]. if iv_number is not INITIAL. lv_num = iv_number. APPEND LINES OF lt_guid from 1 to iv_number to et_guidlist. else. lv_num = 100. APPEND LINES OF lt_guid from 1 to lv_num to et_guidlist. endif. else. lt_guid[] = lt_guidlist[]. if iv_number is not INITIAL. lv_num = iv_number. APPEND LINES OF lt_guid from 1 to iv_number to et_guidlist. else. lv_num = 100. APPEND LINES OF lt_guid from 1 to lv_num to et_guidlist. endif. endif. DESCRIBE TABLE lt_guid LINES lv_lines. if lv_lines > lv_num. move lv_num to lv_help_par1. MOVE lv_help_par1 TO lv_par1. CALL FUNCTION 'BALW_BAPIRETURN_GET2' EXPORTING type = 'S' cl = 'CRM_BSP_FRAME' number = '017' par1 = lv_par1 IMPORTING return = ls_return. APPEND ls_return TO et_return. endif. endif. endif. endmethod.
Activate the BADI.
Now you are done and the search should work.
Comments (2)
Aug 19, 2010
Shobhit Srivastava says:
Good Sanila, it is really helpful. Thanks, ShobhitGood Sanila, it is really helpful. Thanks, Shobhit
Sep 16, 2011
Simobi says:
Hello Sanila, i really appreciated your contribution. Right now i am nearly su...Hello Sanila,
i really appreciated your contribution.
Right now i am nearly substituting the order standard search, since all needed fields are located in the position of an order. Therefore i enhanced the search structure with an append containing the requested fields for the query. Also i extended the result structure.
The logic has been implemented in the corresponding BAdI into the Method IF_CRM_RF_Q1O_SEARCH~SEARCH.
I didn't implement any drop-down functionality so i didn't code any getter.
Needless to say, the query isn't working. I used this code in the method of the BAdI:
Do you have a clue why this isn't working? Have I to implement more?
Many thanks in advance.
-Sim Obi