二维码

[教程] ONE CLICK ACTIONS

Twilight发表于 2016-02-05 22:51hes 最后回复于 2017-06-05 17:12 [复制链接] 856 1

When we open any service contract, we can see these one click actions in the item assignment block. These actions help us to edit some important fields of line item there itself in the table view. We need to not navigate to item overview page to edit it and also we can delete that item on the same assignment block.

Let us provide one click action for a table view. Here I am going to add OCAs to the table view that I created in the chapter VALUE NODE CONCEPT. However procedure that we follow applies to any table view.

Step1.
We need to add one value attribute with name THTMLB_OCA with type CRM_THTMLB_ONE_CLICK_ACTION to the context node of table view.

Go to the table view context node for which you want to implement ONE CLICK ACTIONS. Add a value attribute as mentioned above.  Kindly see the below screen shots for reference.
OCA 1.jpg
OCA 2.jpg

Complete the wizard. We have created the attribute.
Step2.
Move the newly created attribute to the displayed fields section on the view configuration tab.
OCA 3.jpg

Step3.
Go to the context node class of table and redefine the method GET_OCA_T_TABLE.
OCA 4.jpg

Write the following code inside that method and activate the method. In this method we have added buttons.
  1. METHOD get_oca_t_table.

  2.   DATA:ls_one_click_action TYPE crmt_thtmlb_one_click_action.

  3.   ls_one_click_action-id         = 'EDIT'.
  4.   ls_one_click_action-icon       = 'edit.gif'.
  5.   ls_one_click_action-text       = ''.
  6.   ls_one_click_action-tooltip    = 'Edit Record'.
  7.   ls_one_click_action-active     = 'X'.
  8.   APPEND ls_one_click_action TO rt_actions.

  9.   ls_one_click_action-id         = 'DELETE'.
  10.   ls_one_click_action-icon       = 'delete.gif'.
  11.   ls_one_click_action-text       = ''.
  12.   ls_one_click_action-tooltip    = 'Delete Record'.
  13.   ls_one_click_action-active     = 'X'.
  14.   APPEND ls_one_click_action TO rt_actions.

  15. ENDMETHOD.
复制代码

Step4.
We need to tell the framework about newly created value attribute is an OCA type. For that we need to code in the P getter method of new attribute.

If P-getter is greyed out, then just double click on. Framework will ask to create it. Then choose yes. Then write the following code inside the method.
OCA 6.jpg
  1.   METHOD get_p_thtmlb_oca.

  2.     CASE iv_property.
  3.       WHEN if_bsp_wd_model_setter_getter=>fp_fieldtype.
  4.         rv_value = cl_bsp_dlc_view_descriptor=>field_type_oca.
  5.       WHEN if_bsp_wd_model_setter_getter=>fp_onclick.
  6.         rv_value = '_oca'.
  7.       WHEN OTHERS.
  8.     ENDCASE.

  9.   ENDMETHOD.                    "GET_P_THTMLB_OCA
复制代码

Here ‘_oca’ is the event handler name that will be triggered when we click on edit or cancel buttons.


Step5.
Create on event handler with name _oca. (event handler name is case sensitive ).
OCA 5.jpg

Here for two buttons only one event handler is assigned. So whether you click on EDIT button or DELETE button, same event handler will be triggered. So we need to know on which button user has clicked to process our logic.

Write the following code inside the event handler and activate it.
  1. METHOD eh_on_oca.

  2.   DATA:lv_event TYPE string,
  3.        lv_index TYPE c LENGTH 2.

  4.   SPLIT htmlb_event_ex->event_defined AT '.' INTO lv_event lv_index.
  5.   CASE lv_event.
  6.     WHEN 'EDIT'.
  7.     WHEN 'DELETE'.
  8.     WHEN OTHERS.
  9.   ENDCASE.

  10. ENDMETHOD.
复制代码

We are getting the ID of buttons on which user has clicked. Based on the button id, We need to process our own logic.
Test the application by placing a break point in the above event handler.
OCA 8.jpg

Click on any button. I clicked on DELETE button
OCA 7.jpg
回复

使用道具 举报

hes
不错,谢谢楼主分享~
回复

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表