Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Link to Content's target Space :

http://wiki.sdn.sap.com/wiki/display/CRM/CRM+Web+Client+UI+Framework

Applies to:

CRM WebClient UI

Summary

Providing content download option in CRM WebClient UI.

Author(s):  

   Arun Prakash Karuppanan
Company:     Accenture
Created on:    April 15 2010
Author(s) Bio
Arun Prakash Karuppanan is a Software Programmer employed with Accenture, working on CRM implementations

Want to provide content download via the browser in CRM WebClient UI? This wiki will show you how.
There are two ways you can do this. One is using the SICF service and the other is creating a service URL dynamically and using it. The advantage in the SICF option is that the service can be switched off with ease by administrators  in case the situation demands it.

Method 1 - Creating and Using SICF services

Creating SICF node itself is easy. Execute transaction SICF and create your service node in the desired hierarchy available under default host. You may want to use the customer namespace here. In change mode, go to the tab "Handler List" and provide a handler class here. You must create this class beforehand. This class must implement the interface method "IF_HTTP_EXTENSION~HANDLE_REQUEST". For template as to how to use this method, please refer to the class "CL_CHTMLB_CONFIG_TAB_EXCEL_EXP". This is the service used by the "Export to Excel" button in the CHTMLB table view. See how they set the response object to trigger the download.

So now, the service has been created. How to access it? First, note down the path and name of the service.


Then, create the URL using this method.

For example, to access the table view excel service, you can generate the URL in the following way. The iv_query parameter is used to send optional parameters with values to this service. Each parameter should be separated by an & symbol. For example, if you wish to send two parameters "format" and "num_lines",

lv_query = 'format=xml&num_lines=10'. Details on how to fetch these parameters are already available in this  handler class.

Data: lv_url type string,
         lv_query type string.
  rv_url = cl_crm_web_utility=>create_url(
iv_path = '/sap/crm/export_to_excel' "can skip default_host from the path
 iv_absolute = 'X'
 iv_query = lv_query
 iv_in_same_session = 'X'
 iv_no_cookie = 'X'
 iv_server_object = server "Server attribute of Controller Class _IMPL
 ).

Add a button to the view with a onClientClick script attached to it.

<thtmlb:button id = "excelbtn" text = "Download Contents" onClientClick = "window.navigate( '<%= lv_url %>' )" />






Tip:

Sometimes, it is useful to get a reference to the view controller class in the handler method. This may be because we would want to access the context data. Get the page id and include it as a parameter, when you create the URL.

DATA: lr_ctxt TYPE REF TO cl_bsp_page_context.
lr_ctxt ?= me->get_page_context( ).
lv_page_id = lr_ctxt->m_page_id.
CONCATENATE ''page_id=' lv_page_id into lv_query.

Next, in the handler class method, use this page ID to get hold of the controller class.

Data: lr_vc type ref to CL_BSP_WD_VIEW_CONTROLLER. "or the type of your controller class 
CALL METHOD server->request->get_form_data
EXPORTING
name = 'page_id'
CHANGING
data = lv_page_id.lr_vc ?= cl_chtmlb_config_tab_excel_exp=>controller_get( iv_id = lv_page_id ).






Method 2 - Creating & Utilizing Service URLs

Create a handler class and implement this method "IF_CRM_WEB_CALLBACK~HANDLE_REQUEST". Note that this interface is different from that required by the SICF service. The implementation of this method itself is no different from the SICF examples. So, go ahead and put your code there.

Create the URL.

lv_url = cl_crm_web_utility=>create_service_url(
iv_handler_class_name = 'ZCALLBACK_SERVICE_URL'
* iv_controller_id = iv_controller_id
iv_absolute = 'X'
iv_query = lv_id
iv_in_same_session = 'X'
iv_no_cookie = 'X'
* iv_prevent_url_mangling = iv_prevent_url_mangling
).





Add a button attached with a javascript function similar to that mentioned in the SICF method.

Note: This applies to both methods. If you want to create a javascript to be used with the buttons generated in the toolbar and such, you can use the method "
cl_crm_web_utility=>create_service_script" to generate it. In case the script doesn't work as expected, you may want to add a "javascript:window.location=" before the script, take care of the quotes and terminate it with a ';'.

Useful Information

Provide content download service in CRM WebClient UI