Skip to Content
This blog is a sequel to Sending HTML Email from SAP CRM/ERP. Sending HTML Email from SAP CRM/ERP talks about how to generate html email using smartforms and SAPConnect technologies. This one focuses on how to integrate the email generation and notification with business processes in CRM. I would divide the topic into two sections. 1. Define the smartform and handle email notification Email notification in html format is achieved with the following steps: Create the smartform with relevant content. Activate the smartform to generate the function module. Use the generated function module to retrieve the content in html format. Transform the content (eg: html tags) as needed. Use the SAPConnect to send the email. Refer to the Sending HTML Email from SAP CRM/ERP for more information. If you would like to send an email notification in a PDF format, method CRM_ORDER_EXEC_SMART_FORM of class CL_DOC_PROCESSING_CRM_ORDER will be sufficient. No extra coding required. Instead if you like to send an html email notification, you can create a new class in the lines of CL_DOC_PROCESSING_CRM_ORDER and implement the method with code mentioned in Appendix below. 2. Hook the email with output determination in SAP With very little effort, you can implement the functionality to send html email notification, when a change happens in the sales document status. Eg: You can configure the system to send an automatic email to the sold-to-party or payer when the order gets completed. SAP CRM delivers forms for standard business transactions like sales order. Eg: CRM delivers the order smart form(CRM_ORDER_CONFIRMATION_01) . With the help of Output determination, the forms can be converted into the content which can be sent via email or the content can be output to printer or fax. Email notification via output determination in CRM a. Define an Action Profile in IMG using transaction CRMC_ACTION_DEF. This action profile will contain the information about when the action should be activated, and which method in a class need to be called when the action occurs. In CRM, SAP delivers the Implementation class: CL_DOC_PROCESSING_CRM_ORDER Method: CRM_ORDER_EXEC_SMART_FORM You can provide the class and the method you created in step1. Note: You can also use “Create Actions with Wizard” in IMG to create an action profile. b. In IMG Assign the above created action profile to business transaction type. Important transactions Smartforms – create/edit smartforms and smart styles Scot – Outgoing email management (Send, verify status) Reference smartforms in SAP Help portal Output determination in CRM Sending HTML Email from SAP CRM/ERP Appendix

METHOD CRM_HTML_SMART_FORM . *Send the order confirmation email notification in html form * GENERALLY USED CONSTANTS OF GENERIC ORDER INCLUDE: CRM_DIRECT. TYPES: SWC_OBJECT TYPE OBJ_RECORD. DATA: LS_CONTROL_PARAMETERS TYPE SSFCTRLOP. * FUNCTION NAME DATA: FUNCTION_NAME TYPE RS38L_FNAM, DUMMY(254) TYPE C, 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, 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. * FILL INTERNAL STRUCTURE FOR THE OUTPUT OPTIONS LS_OUTPUT_OPTIONS = IS_OUTPUT_OPTIONS. * GET THE FUNCTION NAME FOR THIS SMART FORM CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING FORMNAME = IP_SMART_FORM IMPORTING FM_NAME = FUNCTION_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. *-----------LANGUAGE OF SMART FORM-------------------------------------- * DETERMIN HERE THE LANGUAGE OF THE SMART FORM LS_CONTROL_PARAMETERS = IS_CONTROL_PARAMETERS. LS_CONTROL_PARAMETERS-LANGU = LV_LANGUAGE. *----------------------------------------------------------------------- LO_ORDER ?= IO_APPL_OBJECT. LV_OBJECT_GUID = LO_ORDER->GET_CRM_OBJ_GUID( ). LV_OBJECT_KIND = LO_ORDER->GET_CRM_OBJ_KIND( ). IF NOT GR_ACTION_BADI IS INITIAL. CALL METHOD GR_ACTION_BADI->CHANGE_LANGUAGE_FOR_PRINTING EXPORTING IV_REF_GUID = LV_OBJECT_GUID IV_REF_KIND = LV_OBJECT_KIND IO_PARTNER = IO_PARTNER CHANGING CS_CONTROL_PARAMETERS = LS_CONTROL_PARAMETERS CS_LANGUAGE_TEXTS = LV_LANGUAGE EXCEPTIONS ERROR_OCCURRED = 1 OTHERS = 2. ENDIF. * SET MAIL TITLE SELECT SINGLE CAPTION INTO LS_OUTPUT_OPTIONS-TDTITLE FROM STXFADMT WHERE FORMNAME = IP_SMART_FORM AND LANGU = LS_CONTROL_PARAMETERS-LANGU. IF LS_OUTPUT_OPTIONS-TDTITLE IS INITIAL. SELECT SINGLE CAPTION INTO LS_OUTPUT_OPTIONS-TDTITLE FROM STXFADMT WHERE FORMNAME = IP_SMART_FORM. ENDIF. *CONCATENATE ' ' '&' INTO LS_OUTPUT_OPTIONS-TDTITLE. * LS_OUTPUT_OPTIONS = IS_OUTPUT_OPTIONS. * LS_OUTPUT_OPTIONS-TDTITLE = TEXT-001. REPLACE '&' WITH LS_ORDERADM_H-OBJECT_ID INTO LS_OUTPUT_OPTIONS-TDTITLE. *-----------FILL ARCHIVE PARAMETERS FOR ARCHIVE LINK ------------------- IF IS_OUTPUT_OPTIONS-TDARMOD = '2' OR IS_OUTPUT_OPTIONS-TDARMOD = '3'. * ARCHIVE_INDEX_TAB READ TABLE CT_ARCHIVE_INDEX_TAB INTO LS_ARCHIVE_INDEX INDEX 1. * JUST FILL THE ID OF YOUR ACTUAL BOR OBJECT * ------> * LS_ARCHIVE_INDEX-OBJECT_ID = 'ID_OF_YOUR_BOR_OBJECT'. * ------> IF LS_ARCHIVE_INDEX-OBJECT_ID IS INITIAL. DELETE CT_ARCHIVE_INDEX_TAB INDEX 1. ELSE. MODIFY CT_ARCHIVE_INDEX_TAB FROM LS_ARCHIVE_INDEX INDEX 1. ENDIF. ENDIF. *----------------------------------------------------------------------- CONSTANTS: C_GR_DIR TYPE TDTEXT VALUE 'MYGRAPHICS/'. "#EC NOTEXT DATA: LS_XSFPARAM_LINE TYPE SSFXSFP, LS_HTML TYPE TRFRESULT, LT_GRAPHICS TYPE TSF_XSF_GR. *SET SMARTFORM OUTPUT OPTIONS LS_OUTPUT_OPTIONS-XSFCMODE = 'X'. LS_OUTPUT_OPTIONS-XSF = 'X'. LS_OUTPUT_OPTIONS-XSFOUTMODE = 'A'. LS_OUTPUT_OPTIONS-XSFFORMAT = 'X'. LS_OUTPUT_OPTIONS-TDARMOD = '' . CLEAR LS_OUTPUT_OPTIONS-XSFOUTDEV. LS_XSFPARAM_LINE-NAME = 'GRAPHICS'. "#EC NOTEXT LS_XSFPARAM_LINE-VALUE = 'EXTRACT'. "#EC NOTEXT APPEND LS_XSFPARAM_LINE TO LS_OUTPUT_OPTIONS-XSFPARS. LS_XSFPARAM_LINE-NAME = 'GRAPHICS-DIRECTORY'. "#EC NOTEXT LS_XSFPARAM_LINE-VALUE = C_GR_DIR. APPEND LS_XSFPARAM_LINE TO LS_OUTPUT_OPTIONS-XSFPARS. LS_XSFPARAM_LINE-NAME = 'CONTENT-ID'. "#EC NOTEXT LS_XSFPARAM_LINE-VALUE = 'ENABLE'. "#EC NOTEXT APPEND LS_XSFPARAM_LINE TO LS_OUTPUT_OPTIONS-XSFPARS. * SILENT MODE ON LS_OUTPUT_OPTIONS-TDIMMED = SPACE. LS_OUTPUT_OPTIONS-TDNEWID = SPACE. LS_CONTROL_PARAMETERS-NO_DIALOG = 'X'. "#EC NOTEXT LS_CONTROL_PARAMETERS-DEVICE = ''. "EC NOTEXT * LS_OUTPUT_OPTIONS-BCS_COMMIT = ''. "EC NOTEXT * prepare the content using smartform and sales document CALL FUNCTION FUNCTION_NAME EXPORTING ARCHIVE_INDEX = IS_ARCHIVE_INDEX ARCHIVE_INDEX_TAB = CT_ARCHIVE_INDEX_TAB ARCHIVE_PARAMETERS = IS_ARCHIVE_PARAMETERS CONTROL_PARAMETERS = LS_CONTROL_PARAMETERS * MAIL_APPL_OBJ = IS_MAIL_APPL_OBJ * MAIL_RECIPIENT = IS_MAIL_RECIPIENT * MAIL_SENDER = IS_MAIL_SENDER OUTPUT_OPTIONS = LS_OUTPUT_OPTIONS USER_SETTINGS = IP_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 DOCUMENT_OUTPUT_INFO = ES_DOCUMENT_OUTPUT_INFO JOB_OUTPUT_INFO = ES_JOB_OUTPUT_INFO JOB_OUTPUT_OPTIONS = ES_JOB_OUTPUT_OPTIONS EXCEPTIONS OUTPUT_CANCELED = 1 PARAMETER_ERROR = 2 OTHERS = 3. IF SY-SUBRC = 0. DATA: LT_RETURN TYPE BAPIRET2_TAB, LT_RECEIVERS TYPE TABLE OF SOMLRECI1, LV_MAIL_SUBJECT TYPE SO_OBJ_DES, LV_SEND_PARTNER TYPE BU_PARTNER. * retrieve the sender and recipient from business objects * provided by postprocessing framework DATA: LS_SENDER TYPE SWC_OBJECT, LS_RECIPIENT TYPE SWC_OBJECT, WA_RECEIVER TYPE SOMLRECI1. SWC_CREATE_OBJECT LS_SENDER 'RECIPIENT' SPACE. SWC_OBJECT_FROM_PERSISTENT IS_MAIL_SENDER LS_SENDER. SWC_GET_PROPERTY LS_SENDER 'AddressString' LV_SEND_PARTNER. SWC_CREATE_OBJECT LS_RECIPIENT 'RECIPIENT' SPACE. SWC_OBJECT_FROM_PERSISTENT IS_MAIL_RECIPIENT LS_RECIPIENT. SWC_GET_PROPERTY LS_RECIPIENT 'AddressString' WA_RECEIVER-RECEIVER. SWC_GET_PROPERTY LS_RECIPIENT 'TypeId' WA_RECEIVER-REC_TYPE. WA_RECEIVER-COM_TYPE = 'INT'. "#EC NOTEXT APPEND WA_RECEIVER TO LT_RECEIVERS. concatenate 'Order Confirmation' LS_ORDERADM_H-OBJECT_ID into LV_MAIL_SUBJECT separated by space. "#EC NOTEXT LS_HTML = ES_JOB_OUTPUT_INFO-XMLOUTPUT-TRFRESULT. LT_GRAPHICS[] = ES_JOB_OUTPUT_INFO-XMLOUTPUT-XSFGR[]. DATA: L_GRAPHIC TYPE SSF_XSF_GR, HTML_DATA TYPE TRFRESULT, GRAPHICS TYPE TSF_XSF_GR, LV_SENT_TO_ALL TYPE BOOLEAN, LV_SEND_ADDRESS TYPE ADR6-SMTP_ADDR, LI_SENDER TYPE REF TO IF_SENDER_BCS, RECEIVER TYPE SOMLRECI1, LO_BCS TYPE REF TO CL_BCS, LO_DOC_BCS TYPE REF TO CL_DOCUMENT_BCS, LO_MIME_HELPER TYPE REF TO CL_GBT_MULTIRELATED_SERVICE, LO_RECIPIENT TYPE REF TO IF_RECIPIENT_BCS, L_FILENAME TYPE STRING, LT_SOLI TYPE SOLI_TAB, LT_SOLIX TYPE SOLIX_TAB, LS_SOLI TYPE SOLI, LS_SOLIX TYPE SOLIX, L_HTML_RAW LIKE LINE OF HTML_DATA-CONTENT, HTML_XSTR TYPE XSTRING, HTML_STR TYPE STRING, HTML_LEN TYPE I, L_OFFSET TYPE I, L_LENGTH TYPE I, L_DIFF TYPE I, L_CONTENT_ID TYPE STRING, L_CONTENT_TYPE TYPE W3CONTTYPE, L_OBJ_LEN TYPE SO_OBJ_LEN, GR_XSTR TYPE XSTRING, L_GR_RAW TYPE BAPICONTEN, L_USERNAME TYPE UNAME, L_MAIL_ADDRESS TYPE AD_SMTPADR, WA_RETURN TYPE BAPIRET2, LV_SEND_REQ_BCS TYPE REF TO CX_SEND_REQ_BCS, LV_ADDRESS_BCS TYPE REF TO CX_ADDRESS_BCS, LV_GBT_MIME TYPE REF TO CX_GBT_MIME, LV_BCOM_MIME TYPE REF TO CX_BCOM_MIME, LV_DOCUMENT_BCS TYPE REF TO CX_DOCUMENT_BCS. CLEAR HTML_XSTR. LOOP AT LS_HTML-CONTENT INTO L_HTML_RAW. CONCATENATE HTML_XSTR L_HTML_RAW INTO HTML_XSTR IN BYTE MODE. ENDLOOP. HTML_XSTR = HTML_XSTR(LS_HTML-LENGTH). CALL FUNCTION 'SCP_TRANSLATE_CHARS' "#EC NOTEXT EXPORTING INBUFF = HTML_XSTR INCODE = '4110' " UTF-8 "#EC NOTEXT * OUTCODE = '0000' " ACTUAL CODEPAGE CSUBST = 'X' "#EC NOTEXT SUBSTC_SPACE = 'X' "#EC NOTEXT IMPORTING OUTBUFF = HTML_STR OUTUSED = HTML_LEN EXCEPTIONS OTHERS = 1. * CHANGE ENCODING UTF-8 TO LATIN1 REPLACE ALL OCCURRENCES OF 'UTF-8' IN HTML_STR WITH 'iso-8859-1' IGNORING CASE. "#EC NOTEXT *HACK THE HTML CODE GENERATED BY SMARTFORM TO MAKE THE *EXTERNAL IMAGES APPEAR AS  TAG IN HTML REPLACE ALL OCCURRENCES OF '' IN HTML_STR WITH '/>' IGNORING CASE. "#EC NOTEXT REPLACE ALL OCCURRENCES OF '' IN HTML_STR WITH '' IGNORING CASE. "#EC NOTEXT REPLACE ALL OCCURRENCES OF '<' IN HTML_STR WITH '<' IGNORING CASE. "#EC NOTEXT REPLACE ALL OCCURRENCES OF '>' IN HTML_STR WITH '>' IGNORING CASE. "#EC NOTEXT HTML_LEN = STRLEN( HTML_STR ). L_OFFSET = 0. L_LENGTH = 255. WHILE L_OFFSET < HTML_LEN. L_DIFF = HTML_LEN - L_OFFSET. IF L_DIFF > L_LENGTH. LS_SOLI-LINE = HTML_STR+L_OFFSET(L_LENGTH). ELSE. LS_SOLI-LINE = HTML_STR+L_OFFSET(L_DIFF). ENDIF. APPEND LS_SOLI TO LT_SOLI. ADD L_LENGTH TO L_OFFSET. ENDWHILE. CREATE OBJECT LO_MIME_HELPER. CALL METHOD LO_MIME_HELPER->SET_MAIN_HTML EXPORTING CONTENT = LT_SOLI FILENAME = 'SAPWEBFORM.HTM' "#EC NOTEXT DESCRIPTION = 'SAP WEB FORM'. "#EC NOTEXT *prepare the graphic content from the smartform LOOP AT LT_GRAPHICS INTO L_GRAPHIC. CLEAR GR_XSTR. LOOP AT L_GRAPHIC-CONTENT INTO L_GR_RAW. CONCATENATE GR_XSTR L_GR_RAW-LINE INTO GR_XSTR IN BYTE MODE. ENDLOOP. GR_XSTR = GR_XSTR(L_GRAPHIC-LENGTH). L_OFFSET = 0. L_LENGTH = 255. CLEAR LT_SOLIX[]. WHILE L_OFFSET < L_GRAPHIC-LENGTH. L_DIFF = L_GRAPHIC-LENGTH - L_OFFSET. IF L_DIFF > L_LENGTH. LS_SOLIX-LINE = GR_XSTR+L_OFFSET(L_LENGTH). ELSE. LS_SOLIX-LINE = GR_XSTR+L_OFFSET(L_DIFF). ENDIF. APPEND LS_SOLIX TO LT_SOLIX. ADD L_LENGTH TO L_OFFSET. ENDWHILE. CONCATENATE C_GR_DIR L_GRAPHIC-GRAPHICS '.BMP' INTO L_FILENAME. "#EC NOTEXT CONCATENATE C_GR_DIR L_GRAPHIC-GRAPHICS '.BMP' INTO L_CONTENT_ID. "#EC NOTEXT L_CONTENT_TYPE = L_GRAPHIC-HTTPTYPE. L_OBJ_LEN = L_GRAPHIC-LENGTH. CALL METHOD LO_MIME_HELPER->ADD_BINARY_PART EXPORTING CONTENT = LT_SOLIX FILENAME = L_FILENAME EXTENSION = 'BMP' "#EC NOTEXT DESCRIPTION = 'GRAPHIC IN BMP FORMAT' "#EC NOTEXT CONTENT_TYPE = L_CONTENT_TYPE LENGTH = L_OBJ_LEN CONTENT_ID = L_CONTENT_ID. ENDLOOP. TRY. LO_DOC_BCS = CL_DOCUMENT_BCS=>CREATE_FROM_MULTIRELATED( I_SUBJECT = LV_MAIL_SUBJECT I_MULTIREL_SERVICE = LO_MIME_HELPER ). CATCH CX_DOCUMENT_BCS INTO LV_DOCUMENT_BCS. * ERROR HANDLING CLEAR WA_RETURN. WA_RETURN-TYPE = 'E'. "#EC NOTEXT MOVE LV_DOCUMENT_BCS->GET_LONGTEXT( ) TO WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE LT_RETURN. EXIT. CATCH CX_BCOM_MIME INTO LV_BCOM_MIME. CLEAR WA_RETURN. WA_RETURN-TYPE = 'E'. "#EC NOTEXT MOVE LV_BCOM_MIME->GET_LONGTEXT( ) TO WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE LT_RETURN. EXIT. CATCH CX_GBT_MIME INTO LV_GBT_MIME. CLEAR WA_RETURN. WA_RETURN-TYPE = 'E'. "#EC NOTEXT MOVE LV_GBT_MIME->GET_LONGTEXT( ) TO WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE LT_RETURN. EXIT. ENDTRY. * REUSE THE CONTENT PREPARED FOR ALL RECEIVERS LOOP AT LT_RECEIVERS INTO RECEIVER. L_MAIL_ADDRESS = RECEIVER-RECEIVER. * CREATE SEND_REQUEST TRY. LO_BCS = CL_BCS=>CREATE_PERSISTENT( ). LO_BCS->SET_DOCUMENT( I_DOCUMENT = LO_DOC_BCS ). CATCH CX_SEND_REQ_BCS INTO LV_SEND_REQ_BCS. CLEAR WA_RETURN. WA_RETURN-TYPE = 'E'. "#EC NOTEXT MOVE LV_SEND_REQ_BCS->GET_LONGTEXT( ) TO WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE LT_RETURN. EXIT. ENDTRY. * CREATE SENDER CLASS CL_CAM_ADDRESS_BCS DEFINITION LOAD. TRY. IF L_USERNAME NS '@'. "#EC NOTEXT L_USERNAME = LV_SEND_PARTNER . TRANSLATE L_USERNAME TO UPPER CASE. "#EC TRANSLANG LI_SENDER ?= CL_SAPUSER_BCS=>CREATE( L_USERNAME ). ELSE. DATA: L_FROM_MAIL_ADDRESS TYPE AD_SMTPADR. L_FROM_MAIL_ADDRESS = L_USERNAME. LI_SENDER ?= CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( I_ADDRESS_STRING = L_FROM_MAIL_ADDRESS ). ENDIF. CALL METHOD LO_BCS->SET_SENDER EXPORTING I_SENDER = LI_SENDER. CATCH CX_ADDRESS_BCS INTO LV_ADDRESS_BCS. * ERROR HANDLING CLEAR WA_RETURN. WA_RETURN-TYPE = 'E'. "#EC NOTEXT MOVE LV_ADDRESS_BCS->GET_LONGTEXT( ) TO WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE LT_RETURN. EXIT. CATCH CX_SEND_REQ_BCS INTO LV_SEND_REQ_BCS. * FAILED TO ADD A RECIPIENT CLEAR WA_RETURN. WA_RETURN-TYPE = 'E'. "#EC NOTEXT MOVE LV_SEND_REQ_BCS->GET_LONGTEXT( ) TO WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE LT_RETURN. EXIT. ENDTRY. * CREATE RECIPIENT TRY. LO_RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( I_ADDRESS_STRING = L_MAIL_ADDRESS ). CATCH CX_ADDRESS_BCS INTO LV_ADDRESS_BCS. * ERROR HANDLING CLEAR WA_RETURN. WA_RETURN-TYPE = 'W'. "#EC NOTEXT MOVE LV_ADDRESS_BCS->GET_LONGTEXT( ) TO WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE LT_RETURN. CONTINUE. ENDTRY. TRY. LO_BCS->ADD_RECIPIENT( I_RECIPIENT = LO_RECIPIENT ). CATCH CX_SEND_REQ_BCS INTO LV_SEND_REQ_BCS. * FAILED TO ADD A RECIPIENT CLEAR WA_RETURN. WA_RETURN-TYPE = 'W'. "#EC NOTEXT MOVE LV_SEND_REQ_BCS->GET_LONGTEXT( ) TO WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE LT_RETURN. CONTINUE. ENDTRY. * SEND TRY. * RECEIPTS ONLY FOR ERRORS CALL METHOD LO_BCS->SEND_REQUEST->SET_REQUESTED_STATUS EXPORTING I_REQUESTED_STATUS = 'N'. "#EC NOTEXT LV_SENT_TO_ALL = LO_BCS->SEND( ). CATCH CX_SEND_REQ_BCS INTO LV_SEND_REQ_BCS. CLEAR WA_RETURN. WA_RETURN-TYPE = 'E'. "#EC NOTEXT MOVE LV_SEND_REQ_BCS->GET_LONGTEXT( ) TO WA_RETURN-MESSAGE. INSERT WA_RETURN INTO TABLE LT_RETURN. * ERROR HANDLING EXIT. ENDTRY. ENDLOOP. " END LOOP AT LT_RECEIVERS COMMIT WORK. ES_JOB_OUTPUT_INFO-OUTPUTDONE = 'X'. * SET THE SUCCESS INFORMATION WA_RETURN-TYPE = 'I'. "#EC NOTEXT WA_RETURN-MESSAGE = 'MAIL SENT SUCCESSFULLY'. "#EC NOTEXT INSERT WA_RETURN INTO TABLE LT_RETURN. * SET STATUS PRINTED INTO THE CRM ORDER CALL FUNCTION 'CRM_STATUS_SET_INTERN' EXPORTING IV_OBJNR = LV_OBJECT_GUID IV_STATUS = GC_STATUS-PRINTED XNOAUTO = TRUE EXCEPTIONS OBJECT_NOT_FOUND = 1 STATUS_INCONSISTENT = 2 STATUS_NOT_ALLOWED = 3 OTHERS = 4. ELSE. CASE SY-SUBRC. WHEN 1. MESSAGE E016(SPPF_MEDIA) INTO DUMMY. WHEN 2. MESSAGE E017(SPPF_MEDIA) WITH FUNCTION_NAME INTO DUMMY. WHEN 3. MESSAGE E018(SPPF_MEDIA) WITH FUNCTION_NAME INTO DUMMY. ENDCASE. CALL METHOD CL_LOG_PPF=>ADD_MESSAGE EXPORTING IP_PROBLEMCLASS = '1' IP_HANDLE = IP_APPLICATION_LOG. ENDIF. * GET ERROR TABLE CALL FUNCTION 'SSF_READ_ERRORS' IMPORTING ERRORTAB = ET_ERROR_TAB. * FILL ERROR INTO CRM_ORDER STATUS LOOP AT ET_ERROR_TAB INTO LV_ERROR_TAB_WRK WHERE MSGTY = GC_MSGTYPE-ERROR. CALL FUNCTION 'CRM_MESSAGE_COLLECT' EXPORTING IV_CALLER_NAME = GC_OBJECT_NAME-ORDER IV_MSGNO = LV_ERROR_TAB_WRK-MSGNO IV_MSGID = LV_ERROR_TAB_WRK-MSGID IV_MSGTY = LV_ERROR_TAB_WRK-MSGTY IV_MSGV1 = LV_ERROR_TAB_WRK-MSGV1 IV_MSGV2 = LV_ERROR_TAB_WRK-MSGV2 IV_MSGV3 = LV_ERROR_TAB_WRK-MSGV3 IV_MSGV4 = LV_ERROR_TAB_WRK-MSGV4 * IV_MSGTYPE = GC_MSGTYPE-WARNING IV_MSGLEVEL = GC_MSGLEVEL-ADMINISTRATOR EXCEPTIONS NOT_FOUND = 1 APPL_LOG_ERROR = 2 OTHERS = 3. ENDLOOP. ENDMETHOD.
To report this post you need to login first.

10 Comments

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

  1. Tom Wessels
    Dear Pavan,
    I’m using your code example to create e-mail from ServiceDesk message in Solution Manager. Solution Manager is using same CRM functionality: Action Profile – Definition – Processing Type. I created processing Method Z_SD_MESSAGE_EXEC_SMART_FORM with almost exact copy of your source (exept for the archive and the language part). It worked: the message is now in HTML instead of PDF, but it’s still an attachment (SAPWEBFORM.HTM and LOGO.BMP). Is it possible to combine these two in the mailbody itself?
    Kind regards,
    Tom Wessels
    (0) 
  2. Brent Curtis
    This is great info and have used it to create an html email.  It works fine for me but when I have a functional co-worker run it, there is an error:  XSF exception: XSF_PRINT_GRAPHIC WRITE_GRAPHIC Error when getting graphic

    I cannot figure out why.  Any help would be greatly appreciated.

    Brent

    (0) 
    1. Pavan Bayyapu Post author
      Hi Brent,
      Looks like this is an authorization problem. Turn on trace for your colleague in transaction st01. That should provide the missing authorizations.
      Thanks,
      pavan
      (0) 
  3. Dmitry Udot
    Hi Pavan!
    I try to use your code for implementing the emailing notificaton in HTML format. For this aim I have created the new class of copying the standart one CL_DOC_PROCESSING_CRM_ORDER (I used it befor for PDF notification) and creaate in it new method CRM_HTML_SMART_FORM that you published. As a smart-form I use the copy of standart CRM_REMINDER_MAIL_01.

    But when I process the corresponded action in transaction CRMC_ACTION_JOB I have the error items with message:
    Dynamic calling of method CRM_HTML_SMART_FORM in class ZCL_DOC_PROCESSING_CRM_ORDER contained error.
    May be I make smth wrong? Please help.

    (0) 
    1. Pavan Bayyapu Post author
      Hi Dmitry,
      Have a program level break point (break dmitry.)in the method and then execute the action from crmd_order. Then debug through.
      Thanks,
      pavan
      (0) 
  4. Amol Guttal
    Hello,

    I have a problem.I want to display data from a complaint transaction in an e-mail using smart forms.
    I want to display both header and item data.

    We were able to display the header data by inserting the form fields ORDERMADM_H-GUID etc(header table)in the general attribute section of the mail content(created a new text in the main section of pages and windows of a smart form).

    But when we try to display the Item data by inserting the form field ORDERADM_I-GUID etc and hit on check it is giving the following error.

    “@8O@     MAILCONTENT     “ORDERADM_I” is a table without a header line and therefore has no component called “GUID”.”

    @8R@     MAILCONTENT     Field orderadm_I-GUID has no defined value

    Can you please let us know where we are missing on this ?

    Amol

    (0) 
  5. Thomas Hoffmann
    Hello,

    first of all many thanks for this great weblog!
    I am using your code to send html emails from the Solution Manager’s service desk whenever the user  status of a support message is changed.
    Everything is working fine, except one problem:

    Whenever I change the status of a message and save the transaction, the status switches back to the the previous status after saving. The new status is saved though, but can only be seen after re-opening the message.This is very confusing for the users as they always try to save the message several times because they think the status wasn’t saved.

    Any ideas?

    Thomas

    (0) 
  6. Samir Gujar
    Hello Pavan,

    We are using in our code to send HTML email. We are using SAP CRM 2007, and this called in an Action. What we have observed is that whenever this code is called, our status object from service ticket gets deleted, and we get an error.

    Can you please advise, if can still used this code for SAP CRM 2007 or is there a new technique to do it.

    Regards,
    Samir

    (0) 

Leave a Reply