Background:
There is a standard functionality available in SAP CRM, by which E-mail Notifications can be configured for business transactions. We can configure standard actions a by assigning appropriate actions to action profile which in turn assign to Business Transaction Type. The Business Transaction information is captured as smartform pdf and this pdf files is sent as an attachment in the e-mail notifications. This e-mail notification doesn't contain any other information apart form subject and attachment.
Business Scenario:
Sometimes, the business requirement is little bit more and the customer also wants that there should be a proper e-mail text body in e-mail notification apart from smartform PDF attachment. This e-mail should address to the person to which e-mail notification is being sent and it should also has some information about what is to be done on this new lead. For example, lets take a scenario, whenever a new lead is created in the system with status open, a mandatory partner function called 'Lead Distributor', is automatically determined from the territory based on Prospect's attribute, . The business needs an e-mail notification should be sent to the Lead Distributor with the following text and smartform pdf attachment:
Hi Thomas,
You have been identified as the Lead Distributor for this new lead .
Please review and assign this new Lead to an appropriate Employee Responsible and update the Lead status to In Process, indicating that you have appropriately assigned this new Lead to responsible person.
Regards,
SAP CRM System Mgmt Team
Solution:
There is a standard class( CL_DOC_PROCESSING_CRM_ORDER ) available in SAP CRM system which we specify as a processing class for action in business transaction and processing method as CRM_ORDER_EXEC_SMART_FORM. We use this class in actions for smartform pdf e-mail notification, If we use this class then it can send smartform pdf as an attachment in e-mail notification but we cannot add email text body in those e-mail notifications.
To address the above mentioned business requirement, we need to create a copy of the standard class ( CL_DOC_PROCESSING_CRM_ORDER ) as ZCL_DOC_PROCESSING_CRM_ORDER and change the implementation of the method CRM_ORDER_EXEC_SMART_FORM as per the code below. Don't forget to update the processing class as your Z class ( method name would remain same ) in individual action customizing.
IMG Path:
SPRO--->Customer Relationship Management ---->Basic Functions --->Actions --->Actions in Transaction --->Change Actions and Conditions ---->Define Action Profiles and Actions
METHOD crm_order_exec_smart_form . * generally used constants of generic order INCLUDE: crm_direct. DATA: lt_otf TYPE TABLE OF itcoo, ls_otf TYPE itcoo, lt_tline TYPE TABLE OF tline, ls_tline TYPE tline, lt_receivers TYPE TABLE OF somlreci1, ls_receivers TYPE somlreci1, lt_record TYPE TABLE OF solisti1, ls_record TYPE solisti1, * Objects to send mail. lt_objpack TYPE TABLE OF sopcklsti1, ls_objpack TYPE sopcklsti1, lt_objtxt TYPE TABLE OF solisti1, ls_objtxt TYPE solisti1, lt_objbin TYPE TABLE OF solisti1, ls_objbin TYPE solisti1, lt_reclist TYPE TABLE OF somlreci1, ls_reclist TYPE somlreci1, dummy(254) TYPE c, * Work Area declarations wa_objhead TYPE soli_tab, w_ctrlop TYPE ssfctrlop, w_compop TYPE ssfcompop, w_return TYPE ssfcrescl, wa_doc_chng TYPE sodocchgi1, w_data TYPE sodocchgi1, wa_buffer TYPE string,"To convert from 132 to 255 * Variables declarations v_form_name TYPE rs38l_fnam, v_len_in TYPE sood-objlen, v_len_out TYPE sood-objlen, v_len_outn TYPE i, v_lines_txt TYPE i, v_lines_bin TYPE i, ls_archive_index TYPE toa_dara, ls_orderadm_h TYPE crmt_output_orderadm_h_com, ls_activity_h TYPE crmt_output_activity_h_com, ls_lead_h TYPE crmt_output_lead_h_com, ls_opport_h TYPE crmt_output_opport_h_com, ls_orgman_h TYPE crmt_output_orgman_h_com, lt_partner_h TYPE crmt_output_partner_h_comt, ls_pricingdata_h TYPE crmt_output_pricingdata_h_com, ls_sales_h TYPE crmt_output_sales_h_com, ls_shipping_h TYPE crmt_output_shipping_h_com, lt_payplan_d_h TYPE crmt_output_payplan_d_h_comt, ls_customer_h TYPE crmt_output_customer_h_com, ls_cumulat_h TYPE crmt_output_cumulat_h_com, lt_billing_h TYPE crmt_output_billing_h_comt, lt_cancel_h TYPE crmt_output_cancel_h_comt, lt_appointment_h TYPE crmt_output_appointment_h_comt, lt_billplan_d_h TYPE crmt_output_billplan_d_h_comt, lt_billplan_h TYPE crmt_output_billplan_h_comt, lt_status_d_h TYPE crmt_output_status_d_h_comt, lt_status_h TYPE crmt_output_status_h_comt, ls_status_h TYPE crmt_output_status_h_com, lt_srv_subject_h TYPE crmt_output_srv_subject_h_comt, lt_srv_reason_h TYPE crmt_output_srv_reason_h_comt, lt_srv_result_h TYPE crmt_output_srv_result_h_comt, ls_acs_h TYPE crmt_acs_h_com, lt_orderadm_i TYPE crmt_output_orderadm_i_comt, lt_orgman_i TYPE crmt_output_orgman_i_comt, lt_pricingdata_i TYPE crmt_output_pricingdata_i_comt, lt_pricing_i TYPE crmt_output_pricing_i_comt, lt_product_i TYPE crmt_output_product_i_comt, lt_sales_i TYPE crmt_output_sales_i_comt, lt_shipping_i TYPE crmt_output_shipping_i_comt, lt_schedlin_i TYPE crmt_output_schedlin_i_comt, lt_customer_i TYPE crmt_output_customer_i_comt, lt_partner_i TYPE crmt_output_partner_i_comt, lt_item_cstics_i TYPE crmt_item_cstics_tab, lt_billing_i TYPE crmt_output_billing_i_comt, lt_cancel_i TYPE crmt_output_cancel_i_comt, lt_finprod_i TYPE crmt_output_finprod_i_comt, lt_ordprp_i TYPE crmt_output_ordprp_i_comt, lt_appointment_i TYPE crmt_output_appointment_i_comt, lt_billplan_d_i TYPE crmt_output_billplan_d_i_comt, lt_billplan_i TYPE crmt_output_billplan_i_comt, lt_orderadm_i_qt TYPE crmt_output_orderadm_i_qt_comt, lt_orderadm_i_in TYPE crmt_output_orderadm_i_in_comt, lt_schedlin_i_cf TYPE crmt_output_schedlin_i_cf_comt, lt_status_i TYPE crmt_output_status_i_comt, lt_working_set_e_s_bbp TYPE /1cn/working_set_e_s_bbp_t, lv_language LIKE sy-langu, lo_order TYPE REF TO cl_doc_crm_order, lv_object_guid TYPE crmt_object_guid, lv_object_kind TYPE crmt_object_kind, lv_status TYPE jstat, lt_status TYPE TABLE OF jstat, lv_error_tab_wrk TYPE ssferror, ls_output_options TYPE ssfcompop, lv_devtype TYPE rspoptype. CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING formname = ip_smart_form IMPORTING fm_name = v_form_name EXCEPTIONS no_form = 1 no_function_module = 2 OTHERS = 3. IF sy-subrc <> 0. * add an error message to processing protocol MESSAGE i015(sppf_media) WITH ip_smart_form INTO dummy. CALL METHOD cl_log_ppf=>add_message EXPORTING ip_problemclass = '1' ip_handle = ip_application_log. EXIT. ENDIF. * determine the tables of the application CALL FUNCTION 'CRM_OUTPUT_SINGLE_READ' EXPORTING iv_object = io_appl_object iv_smart_form = ip_smart_form ir_partner = io_partner IMPORTING es_output_orderadm_h = ls_orderadm_h es_output_activity_h = ls_activity_h es_output_lead_h = ls_lead_h es_output_opport_h = ls_opport_h es_output_orgman_h = ls_orgman_h es_output_pricingdata_h = ls_pricingdata_h es_output_sales_h = ls_sales_h es_output_shipping_h = ls_shipping_h et_output_partner_h = lt_partner_h et_output_payplan_d_h = lt_payplan_d_h es_output_customer_h = ls_customer_h es_output_cumulat_h = ls_cumulat_h et_output_billing_h = lt_billing_h et_output_cancel_h = lt_cancel_h et_output_appointment_h = lt_appointment_h et_output_billplan_d_h = lt_billplan_d_h et_output_billplan_h = lt_billplan_h et_output_status_d_h = lt_status_d_h et_output_status_h = lt_status_h et_output_srv_subject_h = lt_srv_subject_h et_output_srv_reason_h = lt_srv_reason_h et_output_srv_result_h = lt_srv_result_h es_output_acs_h = ls_acs_h et_output_orderadm_i = lt_orderadm_i et_output_orgman_i = lt_orgman_i et_output_pricingdata_i = lt_pricingdata_i et_output_pricing_i = lt_pricing_i et_output_product_i = lt_product_i et_output_sales_i = lt_sales_i et_output_shipping_i = lt_shipping_i et_output_schedlin_i = lt_schedlin_i et_output_partner_i = lt_partner_i et_item_cstics_i = lt_item_cstics_i et_output_customer_i = lt_customer_i et_output_billing_i = lt_billing_i et_output_cancel_i = lt_cancel_i et_output_finprod_i = lt_finprod_i et_output_ordprp_i = lt_ordprp_i et_output_appointment_i = lt_appointment_i et_output_billplan_d_i = lt_billplan_d_i et_output_billplan_i = lt_billplan_i et_output_orderadm_i_qt = lt_orderadm_i_qt et_output_orderadm_i_in = lt_orderadm_i_in et_output_schedlin_i_cf = lt_schedlin_i_cf et_output_status_i = lt_status_i et_output_wrk_set_e_s_bbp = lt_working_set_e_s_bbp ev_language = lv_language. w_ctrlop-getotf = 'X'. w_ctrlop-no_dialog = 'X'. w_compop-tdnoprev = 'X'. w_compop-tddest = 'LOCL'. CALL FUNCTION v_form_name EXPORTING control_parameters = w_ctrlop output_options = w_compop user_settings = ' ' orderadm_h = ls_orderadm_h activity_h = ls_activity_h lead_h = ls_lead_h opport_h = ls_opport_h orgman_h = ls_orgman_h partner_h = lt_partner_h pricingdata_h = ls_pricingdata_h sales_h = ls_sales_h shipping_h = ls_shipping_h payplan_d_h = lt_payplan_d_h cumulat_h = ls_cumulat_h customer_h = ls_customer_h acs_h = ls_acs_h billing_h = lt_billing_h cancel_h = lt_cancel_h appointment_h = lt_appointment_h billplan_d_h = lt_billplan_d_h billplan_h = lt_billplan_h status_d_h = lt_status_d_h status_h = lt_status_h srv_subject_h = lt_srv_subject_h srv_reason_h = lt_srv_reason_h srv_result_h = lt_srv_result_h orderadm_i = lt_orderadm_i orderadm_i_qt = lt_orderadm_i_qt orderadm_i_in = lt_orderadm_i_in orgman_i = lt_orgman_i pricingdata_i = lt_pricingdata_i pricing_i = lt_pricing_i product_i = lt_product_i sales_i = lt_sales_i schedlin_i = lt_schedlin_i schedlin_i_cf = lt_schedlin_i_cf shipping_i = lt_shipping_i partner_i = lt_partner_i item_cstics_i = lt_item_cstics_i customer_i = lt_customer_i billing_i = lt_billing_i cancel_i = lt_cancel_i finprod_i = lt_finprod_i ordprp_i = lt_ordprp_i appointment_i = lt_appointment_i billplan_d_i = lt_billplan_d_i billplan_i = lt_billplan_i status_i = lt_status_i working_set_e_s_bbp = lt_working_set_e_s_bbp language = lv_language IMPORTING job_output_info = w_return EXCEPTIONS formatting_error = 1 internal_error = 2 send_error = 3 user_canceled = 4 OTHERS = 5. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. lt_otf[] = w_return-otfdata[]. CALL FUNCTION 'CONVERT_OTF' EXPORTING format = 'PDF' max_linewidth = 132 IMPORTING bin_filesize = v_len_in TABLES otf = lt_otf lines = lt_tline EXCEPTIONS err_max_linewidth = 1 err_format = 2 err_conv_not_possible = 3 OTHERS = 4. * Fehlerhandling IF sy-subrc <> 0. ENDIF. LOOP AT lt_tline INTO ls_tline. TRANSLATE ls_tline USING '~'. CONCATENATE wa_buffer ls_tline INTO wa_buffer. ENDLOOP. TRANSLATE wa_buffer USING '~'. DO. ls_record = wa_buffer. APPEND ls_record TO lt_record. SHIFT wa_buffer LEFT BY 255 PLACES. IF wa_buffer IS INITIAL. EXIT. ENDIF. ENDDO. * Attachment REFRESH: lt_reclist, lt_objtxt, lt_objbin, lt_objpack. CLEAR wa_objhead. lt_objbin[] = lt_record[]. ******* Create Message Body **** Title and Description DATA: lv_first_name TYPE string. DATA: lv_text TYPE string. DATA: lv_text_temp TYPE string. DATA: lv_length TYPE int4. DATA: lv_pf_name TYPE string. DATA: lv_new_status_txt TYPE string. DATA: lv_pf_rel_txt1 TYPE string. DATA: lv_pf_rel_txt2 TYPE string. DATA: lv_partner_no TYPE bu_partner. DATA: lv_ppfdpartno TYPE ppfdpartno. DATA: ls_bp_data TYPE bapibus1006_central_person. DATA: lv_rec_email TYPE so_name. DATA: lv_send_email TYPE so_name, lv_sender_name TYPE uname, lv_guid TYPE crmt_object_guid, ls_send_mail TYPE so_rec_ext. IF io_partner IS BOUND. lv_ppfdpartno = io_partner->get_partnno( ). lv_partner_no = lv_ppfdpartno. CALL FUNCTION 'BUPA_CENTRAL_GET_DETAIL' EXPORTING iv_partner = lv_partner_no IMPORTING es_data_person = ls_bp_data. lv_first_name = ls_bp_data-firstname. CONCATENATE 'Hi ' lv_first_name ',' INTO ls_objtxt. APPEND ls_objtxt TO lt_objtxt. APPEND INITIAL LINE TO lt_objtxt. CLEAR ls_objtxt. IF io_partner->get_partnrole( ) = 'Z00000XX'. " Lead Distributor APPEND 'You have been identified as the Lead Distributor for this new lead .' TO lt_objtxt. APPEND INITIAL LINE TO lt_objtxt. APPEND 'Please review and assign this new Lead to an appropriate Employee Responsible and update the Lead status to In Process, indicating that you have appropriately assigned this new Lead to responsible person.' TO lt_objtxt. ENDIF. ENDIF. APPEND INITIAL LINE TO lt_objtxt. APPEND 'Regards,' TO lt_objtxt. APPEND 'SAP CRM System Mgmt Team' TO lt_objtxt. DESCRIBE TABLE lt_objtxt LINES v_lines_txt. READ TABLE lt_objtxt INTO ls_objtxt INDEX v_lines_txt. wa_doc_chng-obj_name = 'New Lead Notification'. wa_doc_chng-sensitivty = 'F'. wa_doc_chng-doc_size = v_lines_txt * 255. CLEAR ls_objpack-transf_bin. ls_objpack-head_start = 1. ls_objpack-head_num = 0. ls_objpack-body_start = 1. ls_objpack-body_num = v_lines_txt. ls_objpack-doc_type = 'RAW'. APPEND ls_objpack TO lt_objpack. **** Attachment * (pdf-Attachment) ls_objpack-transf_bin = 'X'. ls_objpack-head_start = 1. ls_objpack-head_num = 0. ls_objpack-body_start = 1. * Länge des Attachment ermitteln DESCRIBE TABLE lt_objbin LINES v_lines_bin. READ TABLE lt_objbin INTO ls_objbin INDEX v_lines_bin. ls_objpack-doc_size = v_lines_bin * 255 . ls_objpack-body_num = v_lines_bin. ls_objpack-doc_type = 'PDF'. ls_objpack-obj_name = 'Lead Notification'. ls_objpack-obj_descr = 'Lead Notification'. APPEND ls_objpack TO lt_objpack. CLEAR ls_reclist. * fill prepare sender CALL FUNCTION 'GET_RECIPIENT_DATA_PPF' EXPORTING is_recipient = is_mail_sender IMPORTING ep_addressstring = lv_send_email. ls_send_mail = lv_send_email. * begin of note 690147 lv_sender_name = lv_send_email. CALL METHOD cl_pd_po_processing_bbp=>process_bbp_check_sender EXPORTING iv_po_guid = lv_guid CHANGING cv_po_sender = lv_sender_name. ls_send_mail = lv_sender_name. * end of note 690147 * fill mailreclist CALL FUNCTION 'GET_RECIPIENT_DATA_PPF' EXPORTING is_recipient = is_mail_recipient IMPORTING ep_addressstring = lv_rec_email. ls_reclist-receiver = lv_rec_email. ls_reclist-rec_type = 'U'. APPEND ls_reclist TO lt_reclist. CALL FUNCTION 'SO_DOCUMENT_SEND_API1' EXPORTING document_data = wa_doc_chng sender_address = ls_send_mail sender_address_type = 'U' put_in_outbox = 'X' TABLES packing_list = lt_objpack object_header = wa_objhead contents_bin = lt_objbin contents_txt = lt_objtxt receivers = lt_reclist EXCEPTIONS too_many_receivers = 1 document_not_sent = 2 document_type_not_exist = 3 operation_no_authorization = 4 parameter_error = 5 x_error = 6 enqueue_error = 7 OTHERS = 8. IF sy-subrc = 0. IF is_output_options-tdarmod <> 1. * we have to archive by ourselves CALL FUNCTION 'CONVERT_OTF_AND_ARCHIVE' EXPORTING arc_p = is_archive_parameters arc_tab = ct_archive_index_tab archive_copies = is_output_options-tdarccop TABLES otf = es_job_output_info-otfdata EXCEPTIONS error_archiv = 1 error_communicationtable = 2 error_connectiontable = 3 error_kernel = 4 error_parameter = 5 error_format = 6 OTHERS = 7. IF sy-subrc = 0. es_job_output_info-archdone = 'X'. MESSAGE i006(bcs_medium) INTO dummy. CALL METHOD cl_log_ppf=>add_message EXPORTING ip_problemclass = '4' ip_handle = ip_application_log. ELSE. MESSAGE i002(bcs_medium) WITH sy-subrc INTO dummy. CALL METHOD cl_log_ppf=>add_message EXPORTING ip_problemclass = '4' ip_handle = ip_application_log. ENDIF. ENDIF. es_job_output_info-outputdone = sppf_true. MESSAGE i029(bbp_out) WITH ls_reclist-receiver INTO dummy. CALL METHOD cl_log_ppf=>add_message EXPORTING ip_problemclass = '4' ip_handle = ip_application_log. ELSE. * add error messages to processing protocol CASE sy-subrc. WHEN 1. MESSAGE i038(bbp_out) INTO dummy. WHEN 2. MESSAGE i032(bbp_out) INTO dummy. WHEN 3. MESSAGE i033(bbp_out) INTO dummy. WHEN 4. MESSAGE i035(bbp_out) INTO dummy. WHEN 5. MESSAGE i035(bbp_out) INTO dummy. WHEN 6. MESSAGE i037(bbp_out) INTO dummy. WHEN 7. MESSAGE i031(bbp_out) INTO dummy. WHEN 8. MESSAGE i036(bbp_out) INTO dummy. ENDCASE. CALL METHOD cl_log_ppf=>add_message EXPORTING ip_problemclass = '1' ip_handle = ip_application_log. ENDIF. CALL FUNCTION 'SSF_READ_ERRORS' IMPORTING errortab = et_error_tab. ENDMETHOD. "crm_order_exec_smart_form