Header Ads

ABOUT ONE-CLICK ACTIONS.



So called One-Click Actions (OCA later on in the text) are dedicated to table list processing. They offer immediate and discrete operations on any row of a table in a view. In the SAP CRM Web UI, the OCA can be represented by an Icon or a text, they are often used to delete or edit a row. The purpose of this blog is to provide you with a quick introduction on the use of OCA via a case study.


Please consider the following statement from Tim Back & Nadine Beigel (SAP Corp) in a paper on OCA published on August 2009:

"Rules on OCA apply only in case you are using table/cellerator view configuration. The THTMLB table/cellerator view tag itself does not support any One Click Actions." 
imageCASE STUDY.


In our previous blog, How to adapt CRM Web UI descriptions in the runtime ... we approached a case where a Web UI application was built from scratch to meet a particular customer requirement regarding the mass maintainance of business documents. We will keep this sample case to illustrate the use of OCA. The application enables the user to updates the informations regarding the status and the partner profiles, then saves all document at once.
We consequently expect all documents to be successfully saved with the updated information, but circumstances may lead to a situation where several documents cannot be saved. The logical unit of work is the document, meaning each document is saved disregardless of what happens with the other documents.
In this context, the idea about the use of OCA came up with a need to get a status of the processing for each document. An icon is shown besides each row where a problem occurred. Clicking on the icon provides the user with a description of the error encountered, this information is embedded into popup window.

image
HOW TO.


In the Web UI Infrastructure, the Table list is handled as a Context node of type table. Though the definition of the OCA in terms of look, feel and action is location on the context node class, the event it triggers is handled on the level of the Controller like other classical view events.
1. Context node setup
. We focus on the class handling the table, here the context node class is ZL_Z01_DEMO__MASSMAINTAIN0_CN00 

. Firstly modify the method GET_TABLE_LINE_SAMPLE where you declare a new attribute thtmlb_oca. The attribute will appear on your context node. Please bear in mind there's one unique OCA attribute required to declare all possible OCA's. 

method GET_TABLE_LINE_SAMPLE.  
TYPES: BEGIN OF line,   "Demo Flag  
thtmlb_oca  type crm_thtmlb_one_click_action.   
include type Z01_DEMO_GCL.    
TYPES:          
END OF line.   
CREATE DATA rv_sample TYPE line. 
endmethod.


. Create the Getter method GET_THTMLB_OCA for your new field (take any Getter method as a sample). 

. Create the Property method GET_P_THTMLB_OCA (copy the template method _GET_P_XYZ). Feed the method with the code below. This method declares the behaviour of the new Attribute THTMLB_OCA as a One-click Action and also specifies the releted Controller Event to call. 

method GET_P_THTMLB_OCA. Case iv_property.  *field type: one click actions     when if_bsp_wd_model_setter_getter=>fp_fieldtype.       
Rv_value = cl_bsp_dlc_view_descriptor=>field_type_oca.  
*onClick     
when if_bsp_wd_model_setter_getter=>fp_onclick.       
Rv_value = '_ONE_CLICK_ACTION'.                  
"The Event which is called when hitting the icon 
 endcase.
 endmethod. 

. Once an Attribute is declared as a One-click Action, an OCA Getter is systematically called to further define its properties. This extra getter method GET_OCA_T_TABLE is already available on the Context node class. We redefine the method to specify the Icon or Text of any OCA and the associated Id used to identify which OCA is hit by the user. Extra settings include the Tooltips, and the (de)activation of the OCA. This method offers an Index parameter IV_INDEX to locate the row currently processed. In the sample code below, we stored all errors in a global attribute table GT_MessageBoard, the method checks whether a message is available for our row and displays the icon accordingly. 

method GET_OCA_T_TABLE. * e.g. standard one click action 'Edit' and 'Delete'.   data: ls_one_click_action TYPE crmt_thtmlb_one_click_action,         lv_MessageBoard     TYPE Z05_DEMO_GCL,         ZL_CuCo             TYPE REF TO ZL_Z01_DEMO__CUCO01MASSMAI_IMPL.  "Check if a message has been stored on this row "Get the Message Board from the Custom Controller (shared with IMPL & CN00) Read Table GT_MessageBoard      Into  LV_MessageBoard      With Key Index = IV_INDEX. Check sy-subrc eq 0.  "Put the Icon accordingly   ls_one_click_action-id      = 'ERROR'.   ls_one_click_action-icon    = 'ico12_error.gif'. * ls_one_click_action-text    = ''.   ls_one_click_action-tooltip = 'More about the error ...'.   ls_one_click_action-active  = 'X'.   append ls_one_click_action to rt_actions.  endmethod.

2. Controller setup
. We now define the processing of the Event, that is, what happens once the user hits the icon. What happens here is up to your imagination (which most of the time is constrained by your customer's requirements). In this case study, as explained above, the event displays a popup window to show the message collected on the processing of the row. At the declaration of the OCA attribute above, we assigned the event _ONE_CLICK_ACTION, we now create an Event Handler method EH_ON_ONE_CLICK_ACTION with the sample code provided hereafter. The logic retrieves the Icon Id (which Icon hit) and the row index (which row considered) from the available HTMLB import parameter (HTML Business Java). 
method EH_ON_ONE_CLICK_ACTION. 
  DATA: lv_event        TYPE string,      
 lv_index          TYPE string,  
     lv_row_index      TYPE i,    
   lr_col            TYPE REF TO cl_crm_bol_entity,    
   LV_MessageBoard   TYPE Z05_DEMO_GCL,    
   Information_Popup TYPE REF TO IF_BSP_WD_POPUP,     
  lv_text           TYPE string,   
    lv_title          TYPE string,   
    ZL_CuCo           TYPE REF TO ZL_Z01_DEMO__CUCO01MASSMAI_IMPL. 
 * 01 Get the row index and the event   
SPLIT HTMLB_EVENT_EX->event_defined AT '.' INTO lv_event lv_index.  
* 02 Convert row index   
lv_row_index = lv_index. 
 * 03 Investigate which icon has been hit  
 CASE lv_event.     
WHEN 'ERROR'.       
"Locate the Message in the MessageBoard      
 Read Table GT_MessageBoard            Into  LV_MessageBoard            With Key Index = lv_row_index.   
    Check sy-subrc eq 0.       "Call the popup       "-1-      
 lv_text = LV_MessageBoard-Message.     
  call method comp_controller->window_manager->create_popup_2_confirm        
 EXPORTING           iv_title          = lv_title           iv_text           = lv_text           iv_btncombination = if_bsp_wd_window_manager=>CO_BTNCOMB_CLOSE         RECEIVING           rv_result         = Information_Popup.       "-2-    
   Information_Popup->set_on_close_event( iv_view = me                                            
  iv_event_name = 'POPUP_CLOSED' ).       "-3-       
Information_Popup->open( ).     
 WHEN OTHERS.    
ENDCASE. 
endmethod.


Powered by Blogger.