Button to generate and send URL of change request or document

Requirement:

Sometimes you want to send an e-mail with a link to a change request or change document, but there is no feature to generate such a URL / e-mail.

Solution:

In SAP Solution Manager 7.2 such a feature is available as standard feature, but in SAP Solution Manager 7.1 you have to implement it by your own. However it is very easy.

Implementation steps:

  • Add button „Link“ to AIC_CMCR_H/AICCMCROverview and AIC_CMCD_H/AICCMCDOverview. To use icons please use report SHOWICON to search for icon_mail (@1S@) or similar. Then use method cl_ai_crm_utility=>get_icon_name to convert it to an icon source.
  • Add event to AIC_CMCR_H/AICCMCROverview and AIC_CMCD_H/AICCMCDOverview
    • Get admin header data analogous to IF_BSP_WD_TOOLBAR_CALLBACK~GET_BUTTONS
    • Get URL by cl_ai_crm_ui_api=>wd_start_crm_ui_4_display. If you want to use Single Sign On (SSO) by using SAP Netweaver Portal redirect, you have to add something as prefix.
    • Build mailto URL
      • lv_recipient = “.
      • lv_subject = |CR { ls_admin_h-object_id }: { ls_admin_h-description }|.
      • lv_body = |{ lv_document_url }|.
      • lv_url = |mailto:{ lv_recipient }?subject={ cl_http_utility=>escape_url( lv_subject ) }&body={ cl_http_utility=>escape_url( lv_body ) } |.
    • set attribute lc_ui_enhancement->bpca_url_to_start

Known issues:

  • Solution is working for change documents but not for change requests? Ensure that HTML code of AIC_CMCR_H/AICCMCRHeaderEF is processing lc_ui_enhancement->bpca_url_to_start in correct way analogous to AIC_CMCD_H/AICCMCDHeaderEF (No use of iframe. That is a bug in older releases)
  • You want to enable feature for Incidents as well? For incidents the steps are similar (web UI component AIC_INCIDENT_H). Additionally you have to adjust the html web page of AIC_INCIDENT_H/IncidentHeaderEF to process lc_ui_enhancement->bpca_url_to_start.
  • You face the issue that Microsoft Outlook is opening only on first click? You face the issue that solution is working only if details form is visible which is not the case if you collapse it or if you are using tile layout? This is a bug in SAP standard. To solve it you have to perform following addition implementation steps:
    • Create a new web UI component (Z_LINK_POPUP)
    • Create a new form view for it with no context nodes
    • Place the HTML source code which is processing lc_ui_enhancement->bpca_url_to_start. You can add additional information. You can also
    • Assign view to window. Publish window as interface.
    • Define component usage to new UI component in AIC_CMCR_H and AIC_CMCD_H and AIC_INCIDENT_H (ZLinkPopup).
    • Improve event implemented before to generate and open a popup with new UI component as content.

That’s all. It is easy. It is working. It helps a lot.

method EH_ONLINK.
* Added by wizard: Handler for event 'LINK'

  DATA:
    lr_cn             TYPE REF TO cl_bsp_wd_context_node,
    lr_entity         TYPE REF TO cl_crm_bol_entity,
    ls_admin_h        TYPE crmst_adminh_btil,

    lv_portal         TYPE string,
    lv_portlet        TYPE string,
    lv_document_url   TYPE string,

    lv_recipient      TYPE string,
    lv_subject        TYPE string,
    lv_body           TYPE string,
    lv_url            TYPE string,

    lc_ui_enhancement TYPE REF TO cl_aic_ui_enhancment,
    lr_popup          TYPE REF TO if_bsp_wd_popup,
    lv_title          TYPE string.
*   lv_text           TYPE string.

*Get Current Business Transaction.
  lr_cn = me->get_context_node( gc_cn_btadminh ).
  IF lr_cn IS BOUND.
    lr_entity ?= lr_cn->collection_wrapper->get_current( ).
    IF lr_entity IS BOUND.
      lr_entity->get_properties( IMPORTING es_attributes = ls_admin_h ).
    ENDIF.
  ENDIF.

*Get URL of document
  CALL METHOD cl_ai_crm_ui_api=>wd_start_crm_ui_4_display
    EXPORTING
      i_guid      = ls_admin_h-guid
    IMPORTING
      e_link      = lv_document_url.

*Build mailto URL
  lv_recipient = ''.
  lv_subject   = |INC { ls_admin_h-object_id }: { ls_admin_h-description }|.
  lv_body      = |{ lv_document_url }|.
  lv_url       = |mailto:{ lv_recipient }?subject={ cl_http_utility=>escape_url( lv_subject ) }&body={ cl_http_utility=>escape_url( lv_body ) } |.

*Send result to web ui component.
  lc_ui_enhancement = cl_aic_ui_enhancment=>get_instance( ).
  lc_ui_enhancement->bpca_url_to_start = lv_url.

**Generate popup.
*  lv_title = 'Generate e-mail with link to document'(902).
*  lv_text  = lv_url.
*  CALL METHOD comp_controller->window_manager->create_popup_2_confirm
*    EXPORTING
*      iv_title          = lv_title
*      iv_text           = lv_text
*      iv_btncombination = comp_controller->window_manager->co_btncomb_ok
*    RECEIVING
*      rv_result         = lr_popup.
*
**Open popup.
*  lr_popup->open( ).

*Generate popup.
  lv_title = 'Generate e-mail with link to document'(902).
  CALL METHOD comp_controller->window_manager->create_popup
    EXPORTING
      iv_interface_view_name = 'Z_LINK_POPUP/MainWindow'
      iv_usage_name          = 'ZLinkPopup'
      iv_title               = lv_title
    RECEIVING
      rv_result              = lr_popup.

*Open popup.
  lr_popup->open( ).

endmethod.
POPUP.HTML

<%@page language="abap" %>
<%@extension name="thtmlb" prefix="thtmlb" %>
<%@extension name="chtmlb" prefix="chtmlb" %>
<%@extension name="bsp" prefix="bsp" %>
<%-- <thtmlb:grid cellSpacing = "1"
     columnSize  = "8"
     height      = "100%"
     rowSize     = "6"
     width       = "100%" />  --%>
<%-- Check if the pop-up needs to be opened form the BPCA url due to BPCA integration --%>
<%
DATAMV_URL_OPENNED       TYPE STRING.
DATAlc_ui_enhancement    TYPE REF TO    cl_aic_ui_enhancment.
lc_ui_enhancement cl_aic_ui_enhancment=>get_instance).
IF lc_ui_enhancement->bpca_url_to_start IS NOT INITIAL AND
cl_http_utility=>is_valid_urllc_ui_enhancement->bpca_url_to_start abap_true.
Concatenate '"' lc_ui_enhancement->bpca_url_to_start '"' INTO MV_URL_OPENNED.
%>
<script type="text/javascript">
window.open(<%= mv_url_openned %>,"","scrollbars=yes");
window.close();
</script>
Microsoft Outlook should open automatically.<br>Please click <a href=<%= mv_url_openned %>>here</a> if not.
<%
CLEAR lc_ui_enhancement->bpca_url_to_start.
ENDIF.
%>