email alert with a link to the transaction on crm ui

Upload: sastry

Post on 10-Oct-2015

10 views

Category:

Documents


0 download

DESCRIPTION

Email Alert with link

TRANSCRIPT

  • 5/20/2018 Email Alert With a Link to the Transaction on CRM UI

    1/8

    Email Alert with a link to the transaction on CRM UI

    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

    Letslook at the SAP standard action profile ACTIVITYwhich is quite close to what we want to do.

    Action ProfileACTIVITY

    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)

    http://scn.sap.com/servlet/JiveServlet/showImage/102-51128-2-362234/1.png
  • 5/20/2018 Email Alert With a Link to the Transaction on CRM UI

    2/8

    Processing TypeSmart Forms Mail

    http://scn.sap.com/servlet/JiveServlet/showImage/102-51128-2-362236/3.pnghttp://scn.sap.com/servlet/JiveServlet/showImage/102-51128-2-362235/2.pnghttp://scn.sap.com/servlet/JiveServlet/showImage/102-51128-2-362236/3.pnghttp://scn.sap.com/servlet/JiveServlet/showImage/102-51128-2-362235/2.png
  • 5/20/2018 Email Alert With a Link to the Transaction on CRM UI

    3/8

    TipIf you want the email alert to be sent to only once per person then on the action definition set the

    ActionMergingproperty to SetHighest Number of Processed Actionswhich will enable the Action

    Mergingtab 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.

    http://scn.sap.com/servlet/JiveServlet/showImage/102-51128-2-362251/5.pnghttp://scn.sap.com/servlet/JiveServlet/showImage/102-51128-2-362249/4.pnghttp://scn.sap.com/servlet/JiveServlet/showImage/102-51128-2-362251/5.pnghttp://scn.sap.com/servlet/JiveServlet/showImage/102-51128-2-362249/4.png
  • 5/20/2018 Email Alert With a Link to the Transaction on CRM UI

    4/8

    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. Addline below after this line.

    ls_output_options-urlcall = 'Z_ALERT'.

    http://scn.sap.com/servlet/JiveServlet/showImage/102-51128-2-362254/8.pnghttp://scn.sap.com/servlet/JiveServlet/showImage/102-51128-2-362253/7.pnghttp://scn.sap.com/servlet/JiveServlet/showImage/102-51128-2-362252/6.pnghttp://scn.sap.com/servlet/JiveServlet/showImage/102-51128-2-362254/8.pnghttp://scn.sap.com/servlet/JiveServlet/showImage/102-51128-2-362253/7.pnghttp://scn.sap.com/servlet/JiveServlet/showImage/102-51128-2-362252/6.pnghttp://scn.sap.com/servlet/JiveServlet/showImage/102-51128-2-362254/8.pnghttp://scn.sap.com/servlet/JiveServlet/showImage/102-51128-2-362253/7.pnghttp://scn.sap.com/servlet/JiveServlet/showImage/102-51128-2-362252/6.png
  • 5/20/2018 Email Alert With a Link to the Transaction on CRM UI

    5/8

    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: TYPE LINE OF ttxctoken.

    * extraxt order_id

    READ TABLE data ASSIGNING

    WITH KEY code = 'ST'.IF IS ASSIGNED.

    lv_order_id = -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'

    http://scn.sap.com/servlet/JiveServlet/showImage/102-51128-2-362273/9.png
  • 5/20/2018 Email Alert With a Link to the Transaction on CRM UI

    6/8

    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.

  • 5/20/2018 Email Alert With a Link to the Transaction on CRM UI

    7/8

    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 DefineConditions.Here you can specify conditions likedontsend the alert If

    the status is closed etc.

    4. End resultwould 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 thetransaction 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.

    http://scn.sap.com/servlet/JiveServlet/showImage/102-51128-2-362274/10.png
  • 5/20/2018 Email Alert With a Link to the Transaction on CRM UI

    8/8

    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.

    http://scn.sap.com/servlet/JiveServlet/showImage/102-51128-2-362275/11.png