Skip to Content

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

/wp-content/uploads/2014/01/1_362234.png

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)

/wp-content/uploads/2014/01/2_362235.png

Processing Type – Smart Forms Mail

/wp-content/uploads/2014/01/3_362236.png

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.

/wp-content/uploads/2014/01/4_362249.png

/wp-content/uploads/2014/01/5_362251.png

2. Prerequisites

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

/wp-content/uploads/2014/01/6_362252.png

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.

/wp-content/uploads/2014/01/7_362253.png

/wp-content/uploads/2014/01/8_362254.png

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.

/wp-content/uploads/2014/01/9_362273.png

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.

/wp-content/uploads/2014/01/10_362274.png

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.

/wp-content/uploads/2014/01/11_362275.png

  • 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.
To report this post you need to login first.

8 Comments

You must be Logged on to comment or reply to a post.

  1. akshay ruia

    Hi,

    What logic have u written in routine add_url_param.

    Can u write the complete logic step wise in words. It would be really greatful.

    Thanks,

    Akshay

    (0) 
  2. Sanket Chimalwar

    Hi Gaurav,

    Thanks for this post. I was missing something in my code and ur code helped to solve that mystery in the Z function module. But i face something different now. In the SOST when i see the details of my mail. I see a number ( Object_id ) as hyperlink ( example 70203 ) as expected and a hyperlink for that number and when i actually receive the email, instead of the number with hyperlink i receive the link.


    As an example -:

    OBJECT_ID ( 70203) is to be masked by http://www.google.com

    IN SOST i see the following in my mail body

    Transaction ID : 70203

    But in actual mail i get

    Transaction ID : http://www.google.com

    Do you have any idea why this happens ??

    Kind regards

    Sanket

    (0) 
        1. Gaurav walia Post author

          Hi Sanket,

          In this article here I’ve described a PDF output. If HTML isn’t a requirement then you can change the HTML output to PDF output easily in SCOT settings.

          Kind regards,

          Gaurav

          (0) 

Leave a Reply