Use BAdI to link appointment to a given opportunity during creation

版权声明:本文为博主汪子熙原创文章,未经博主允许不得转载。 https://blog.csdn.net/i042416/article/details/90053805

Requirement

This requirement is raised by customer. They have extended a new field “Opportunity id” in My Appointment creation page. During appointment creation, customer choose an opportunity from this extension field via value help, and they would like to automatically generate a document history which links the created appointment with this manually chosen opportunity.

Implementation

create one BAdI implementation on spot CRM_APPT_ODATA_ENH with following source code:

  METHOD if_ex_crm_appt_odata~update_appointment_details.
    INCLUDE: crm_object_names_con,
             crm_object_types_con,
             crm_object_kinds_con,
             crm_mode_con.
    DATA: ls_doc_flow     TYPE crmt_doc_flow_com,
          lt_doc_flow     LIKE ct_doc_flow,
          ls_doc_link     TYPE crmt_doc_flow_extd,
          ls_appointment  LIKE LINE OF ct_appointment,
          lt_exception    TYPE crmt_exception_t,
          lt_input_fields TYPE crmt_input_field_tab,
          ls_input        LIKE LINE OF ct_input_fields,
          ls_field        LIKE LINE OF ls_input-field_names.
    IF sy-uname = 'WANGJER'.
      READ TABLE ct_appointment INTO ls_appointment INDEX 1.
      ASSERT sy-subrc = 0.
      ls_doc_flow-ref_handle = ls_appointment-ref_handle.
      ls_doc_flow-ref_kind   = 'A'.
      ls_doc_link-objkey_a   = '0050569F4AEA1ED4BFF22CF79358C400'.
      ls_doc_link-handle_b   = ls_appointment-ref_handle.
      ls_doc_link-brel_kind  = 'A'.
      ls_doc_link-brel_mode  = 'A'.
      ls_doc_link-reltype    = 'VONA'.
      APPEND ls_doc_link TO ls_doc_flow-doc_link.
      INSERT ls_doc_flow INTO TABLE lt_doc_flow.
      CLEAR: ls_input-field_names.
      ls_field = 'OBJKEY_A'.
      INSERT ls_field INTO TABLE ls_input-field_names.
      ls_field-fieldname = 'OBJTYPE_A'.
      INSERT ls_field INTO TABLE ls_input-field_names.
      ls_field-fieldname = 'OBJKEY_B'.
      INSERT ls_field INTO TABLE ls_input-field_names.
      ls_field-fieldname = 'OBJTYPE_B'.
      INSERT ls_field INTO TABLE ls_input-field_names.
      ls_field-fieldname = 'BREL_KIND'.
      INSERT ls_field INTO TABLE ls_input-field_names.
      ls_field-fieldname = 'RELTYPE'.
      INSERT ls_field INTO TABLE ls_input-field_names.
      ls_input-ref_handle = ls_appointment-ref_handle.
      ls_input-ref_kind    = 'A'.
      ls_input-objectname  = gc_object_name-doc_flow.
      INSERT ls_input INTO TABLE lt_input_fields.
      CALL FUNCTION 'CRM_ORDER_MAINTAIN'
        IMPORTING
          et_exception      = lt_exception
        CHANGING
          ct_input_fields   = lt_input_fields
          ct_doc_flow       = lt_doc_flow
          ct_orderadm_h     = ct_orderadm_h
        EXCEPTIONS
          error_occurred    = 1
          document_locked   = 2
          no_change_allowed = 3
          no_authority      = 4.
    ENDIF.
  ENDMETHOD.

Archievement


Appointment 成功创建之后,代码里hard code的opportunity guid对应的opportunity就会出现在Appointment的Transaction History area里:

clipboard1
要获取更多Jerry的原创文章,请关注公众号"汪子熙":

猜你喜欢

转载自blog.csdn.net/i042416/article/details/90053805