CRM and CX Blogs by Members
Find insights on SAP customer relationship management and customer experience products in blog posts from community members. Post your own perspective today!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

In one of the scenarios an email had to be sent to the employee responsible whenever an activity was assigned to him/her. The email had to contain a hyperlink which when clicked would launch the transaction on CRM Web UI. An easy way of doing that is using PPF Actions.

1. Action Example

Let’s look at the SAP standard action profile “ACTIVITY” which is quite close to what we want to do.

Action Profile – ACTIVITY

Action Definition – ACTIVITY_REMINDER_MAIL (Note – Partner Dependent, which means only when a partner with that partner function is assigned to the transaction will the action be determined)

Processing Type – Smart Forms Mail

TipIf you want the email alert to be sent to only once per person then on the action definition set the “Action Merging” property to “Set Highest Number of Processed Actions” which will enable the “Action Merging” tab where you will be able to specify that the system should allow a maximum of 1 successful action.

2. Prerequisites

A. Copy the smartform CRM_REMINDER_MAIL_01  into ZCRM_REMINDER_MAIL_01 and convert the transaction id into a hyperlink.

B. Create a new class ZCL_DOC_PROCESSING_CRM_ORDER deriving from CL_SF_PROCESSING_PPF and create the methods similar to the SAP class CL_DOC_PROCESSING_CRM_ORDER.

METHOD class_constructor.

  CALL METHOD cl_exithandler=>get_instance
    EXPORTING
      exit_name              = 'CRM_ACTION_BADI'  "#ec notext
      null_instance_accepted = 'X'
    CHANGING
      instance               = gr_action_badi.

ENDMETHOD.

Copy and paste the code from the SAP standard class into the method CRM_ORDER_EXEC_SMART_FORM. After the data definitions in the method add the name of the callback function module as below -

* fill internal structure for the output options
  ls_output_options = is_output_options. “Add line below after this line.
  ls_output_options-urlcall = 'Z_ALERT'.

C. Create the function module Z_ALERT. Make sure you add a default to the parameter IV_BUSINESS_ROLE to point to the crm business role that will be launched when the URL in the smartform is clicked. Make sure that the business role has the outbound plug mapping maintained as shown in the screenshot below.

FUNCTION z_alert.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(IV_BT_ID) TYPE  CRMT_OBJECT_ID_DB OPTIONAL
*"     VALUE(IV_BUSINESS_ROLE) TYPE  STRING DEFAULT 'ZYOURROLE'
*"     VALUE(IV_ACTION) TYPE  STRING DEFAULT 'B'
*"  CHANGING
*"     REFERENCE(DATA) TYPE  TTXCTOKEN
*"----------------------------------------------------------------------

  INCLUDE rstxscad.
  CONSTANTS: cv_line_length TYPE i VALUE 42.

  DATA: l_str TYPE string.

  DATA: lv_base_url        TYPE string,
        lv_bp              TYPE bu_partner,
        lv_sso_active      TYPE flag.

  DATA: lr_appl_model TYPE REF TO if_bsp_wd_appl_model.

  DATA:
        lv_offset      TYPE i,
        lv_length      TYPE i,
        lv_guid_char   TYPE sysuuid_c,
        lv_guid        TYPE sysuuid_x,
        lv_url         TYPE string,
        ls_xctoken     TYPE LINE OF ttxctoken,
        lv_order_id    TYPE crmt_object_id_db.

  FIELD-SYMBOLS: <ls_xctoken>   TYPE LINE OF ttxctoken.

* extraxt order_id
  READ TABLE data ASSIGNING <ls_xctoken>
        WITH KEY code = 'ST'.

  IF <ls_xctoken> IS ASSIGNED.
    lv_order_id = <ls_xctoken>-string.

    IF lv_order_id IS NOT INITIAL.

      cl_bsp_wd_appl_model=>get_appl_model(
      EXPORTING
        iv_bsp_appl   = 'CRM_UI_START'
        iv_model_type = 'CL_BSP_WD_APPL_MODEL_RTTI'
        RECEIVING
        rv_model      = lr_appl_model
      EXCEPTIONS
        OTHERS          = 1 ).

      CHECK lr_appl_model IS BOUND.

      lv_base_url = lr_appl_model->get_start_url( ).
      gv_url = lv_base_url.

*  PERFORM add_url_param USING 'sap-language' sy-langu.

      IF iv_business_role IS NOT INITIAL.
        PERFORM add_url_param USING 'saprole' iv_business_role.
      ENDIF.

      PERFORM add_url_param USING 'crm-object-type' 'BT126H_APPT'.
      PERFORM add_url_param USING 'crm-object-action' iv_action.
      PERFORM add_url_param USING 'crm-object-keyname' 'OBJECT_ID'.
      PERFORM add_url_param USING 'crm-object-value' lv_order_id.

      DELETE data WHERE code = 'LK'.

      lv_length = strlen( gv_url ).
      lv_offset = 0.

      ls_xctoken-code = 'LK'.
      ls_xctoken-line = -1.
      ls_xctoken-len  = cv_line_length.
      ls_xctoken-string = space.

      WHILE lv_length > 0.

        ls_xctoken-code = 'LK'.
        ls_xctoken-len  = cv_line_length.
        ls_xctoken-string = space.
        ls_xctoken-line = ls_xctoken-line + 1.

        IF lv_length > cv_line_length.
          ls_xctoken-string+4(cv_line_length) = gv_url+lv_offset.
          lv_offset = lv_offset + cv_line_length.
          lv_length = lv_length - cv_line_length.
        ELSE.
          ls_xctoken-string+4(lv_length) = gv_url+lv_offset.
          ls_xctoken-len = lv_length.
          lv_length      = 0.
        ENDIF.
        APPEND ls_xctoken TO data.

      ENDWHILE.
    ENDIF.
  ENDIF.

ENDFUNCTION.

In the function group include add the following -

DATA gv_url(4096) TYPE c.

FORM add_url_param USING iv_param  TYPE string
      iv_value  TYPE ANY.


  IF gv_url CA '?'.
    CONCATENATE gv_url '&' iv_param '=' iv_value INTO gv_url. "#EC NOTEXT
  ELSE.
    CONCATENATE gv_url '?' iv_param '=' iv_value INTO gv_url. "#EC NOTEXT
  ENDIF.

ENDFORM.

1.   3. Action Definition

With all the prerequisite steps complete we are now ready to create the action. I assume there is already an action profile assigned to the transaction type in context here. We can now go ahead and create the action similar to the SAP standard action only to replace the action handler class to our Z class and the smartform to our Z smartform.

After the action definition is complete the next step is to define the action condition which can be done using the IMG Activity “Define Conditions”. Here you can specify conditions like don’t send the alert If the status is closed etc.

4. End result would be that whenever an employee is assigned to that transaction an email will go out to the employee which will contain a hyperlink on the transaction ID which when clicked will open the transaction on CRM Web UI using the role specified in the call back function module.

1.   5. Troubleshooting

  • Enable the Actions assignment block on the transaction and check the determination and execution trace.
  • For the email to go out to the employee the email address has to be maintained on the address information of the employee record.
  • Check SCOT settings to make sure that an SMTP node is determined for the email address.
  • Smartforms will be emailed as PDF attachments based on the SCOT setting
  • In development systems the job that sends email out is usually not scheduled so you might have to push emails out manually using SOST.

  • If everything looks ok then run an authorization trace (ST05) to check if a missing auth is preventing from email from being sent. Usually the object S_OC_SEND is the cause of the authorization problem.
8 Comments