Roelof Albers
Read all my blogsWe recently had the requirement to open SAP CRM and search Accounts directly with the given postal code and house number.
Standard SAP options
We first analysed the standard options SAP gives us, like opening/searching objects with the following parameters:
crm-object-type BP_CONTACT
crm-object-action A = search, B = display, C = edit, D = create
crm-object-value GUID
For example, open Contact Person Search
crm-object-type=BP_CONTACT&crm-object-action=A
Or open a single Activity
crm-object-type=BT126_APPT&crm-object-action=B&crm-object-value=<GUID>
This didn’t fit our requirements, since we wanted to search by at least 2 parameters (and potentially more in the future).
Passing parameters the correct way
Our first try was to add the parameters in the URL like this:
?postalcode=1234 AB&housenum=1
But found out that those parameters are stripped off by the framework. Through debugging we found out that the parameters starting with sap- we’re not stripped of the URL, so we are now passing the parameters as:
?sap-postalcode=1234 AB&sap-housenum=1
Reading the parameters
In the implementation class of the view CRMCMP_IC_FRAME/HiddenView of the enhanced component CRMCMP_IC_FRAME, we added the following code to the ON_INIT method:
DATA: lr_gdc TYPE REF TO if_crm_ui_data_context.
DATA: lv_postalcode TYPE string.
DATA: lv_housenum TYPE string.
lv_postalcode = runtime->server->request->get_form_field( ‘sap-postalcode’ ).
lv_housenum = runtime->server->request->get_form_field( ‘sap-housenum’ ).
IF lv_postalcode IS NOT INITIAL AND lv_housenum IS NOT INITIAL.
TRY.
lr_gdc ?= cl_crm_ui_data_context_srv=>get_instance( ).
CALL METHOD lr_gdc->set_data_attribute
EXPORTING
i_value = lv_postalcode
iv_name = ‘postalcode’.
CALL METHOD lr_gdc->set_data_attribute
EXPORTING
i_value = lv_housenum
iv_name = ‘housenum’.
CATCH cx_root.
ENDTRY.
ENDIF.
First we try to read the URL parameters, if found, we add the parameters to the Global Data Context.
Search using the parameters
We enhanced the component ICCMP_BP_SEARCH, and added the following code to the method DO_PREPARE_OUTPUT of the view ICCMP_BP_SEARCH/BuPaSearch.
DATA: lr_gdc TYPE REF TO if_crm_ui_data_context,
lv_postalcode TYPE string,
lv_housenum TYPE string.
* GDC parameters were set in HiddenView->DO_INIT from URL parameters
lr_gdc ?= cl_crm_ui_data_context_srv=>get_instance( ).
TRY.
lr_gdc->get_data_attribute(
EXPORTING
iv_name = ‘postalcode’
IMPORTING
e_value = lv_postalcode
).
CATCH cx_root.
ENDTRY.
TRY.
lr_gdc->get_data_attribute(
EXPORTING
iv_name = ‘housenum’
IMPORTING
e_value = lv_housenum
).
CATCH cx_root.
ENDTRY.
IF lv_postalcode IS NOT INITIAL AND lv_housenum IS NOT INITIAL.
“SET VALUES TO SCREEN
me->typed_context->searchcustomer->set_post_code1(
EXPORTING
attribute_path = ”
value = lv_postalcode
).
me->typed_context->searchcustomer->set_house_num1(
EXPORTING
attribute_path = ”
value = lv_housenum
).
“PERFORM SEARCH
IF gr_window IS NOT BOUND.
gr_window ?= me->view_manager->get_window_controller( ).
ENDIF.
eh_onsearch( ).
ENDIF.
“REMOVE VALUES FROM GDC
TRY.
lr_gdc->set_data_attribute(
EXPORTING
i_value = ”
iv_name = ‘postalcode’
).
CATCH cx_root.
ENDTRY.
TRY.
lr_gdc->set_data_attribute(
EXPORTING
i_value = ”
iv_name = ‘housenum’
).
CATCH cx_root.
ENDTRY.