cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to send Email with HTML layout using CL_BCS class via SAP Transportation Management

jay_d
Explorer
0 Kudos

Hi,

I am new to SAP Transportation Management. I am facing trouble while trying to send a formatted email (with HTML body) for Freight Order. 

So I have a formatted email body maintained in Smartfroms Text Module which looks like this:

jay_d_0-1715950859885.png

Now for the sending email we have implemented the method /BOFU/IF_PPF_SERV_FOR_BO~COMPLETE_SEND which successfully triggers the mail communication. 

Following is the code mentioned in the method:

 

 METHOD /bofu/if_ppf_serv_for_bo~complete_send.

    DATA: lo_recipient TYPE REF TO cl_cam_address_bcs,
          lo_easy_email TYPE REF TO zcl_email,
          lt_emails     TYPE bcsy_smtpa,
          lt_body       TYPE bcsy_text,
          lv_template   TYPE sychar40,
          lt_note       TYPE bcsy_text.

    CALL METHOD /scmtms/cl_print_helper=>get_tor_nodes
      EXPORTING
        it_key          = lt_keys
      IMPORTING
        et_root         = DATA(lt_root)
        et_item_tr      = DATA(lt_item_tr)
        et_party        = DATA(lt_party)
        et_docref       = DATA(lt_docref)
        et_docref_item  = DATA(lt_itemref)
        et_tor_add_info = DATA(lt_additional_info).

    CALL METHOD /scmtms/cl_doc_flow_factory=>get_instance
      EXPORTING
        iv_bo_key   = /scmtms/if_tor_c=>sc_bo_key
      RECEIVING
        ro_doc_flow = DATA(lo_doc_flow_ref).

    CALL METHOD lo_doc_flow_ref->get_doc_flow
      EXPORTING
        iv_direction         = 'A'
        iv_node_key          = /scmtms/if_tor_c=>sc_node-root
        it_key               = lt_keys
      CHANGING
        ct_doc_flow          = lt_root_table
        ct_doc_flow_relation = lt_root_table_relation.

    TRY.
        DATA(ls_root) = lt_root[ 1 ].
        DATA(ls_item) = lt_item_tr[ main_cargo_item = 'X' ].
        DATA(ls_item_tr) = lt_item_tr[ main_cargo_item = '' ].
      CATCH cx_sy_itab_line_not_found.
        EXIT.
    ENDTRY.

	** Other business Logic ommitted **

    CREATE OBJECT lo_easy_email.

    CASE is_ppf_act-ppf_action.
      WHEN 'ZMAIL'.

        TRY.
            lo_recipient = cl_cam_address_bcs=>create_internet_address( i_address_string = "abc@def.com" ).

          CATCH cx_address_bcs.
        ENDTRY.
        io_send->add_recipient( i_recipient = lo_recipient ). " Recipient of Message

        ls_languages-langu1 = l_spras.
        ls_languages-langu2 = 'E'.

        lv_textname = 'Z_MAIL_BODY'.

        SELECT SINGLE COUNT(*) FROM stxfadm
                               WHERE formname   = lv_textname
                               AND   formtype = 'T'
                               AND   masterlang  = l_spras.

        REFRESH : lt_texts.
        CALL FUNCTION 'SSFRT_READ_TEXTMODULE'
          EXPORTING
            i_textmodule       = lv_textname
            i_languages        = ls_languages
          IMPORTING
*           O_LANGU            =
            o_text             = lt_texts
          EXCEPTIONS
            error              = 1
            language_not_found = 2
            OTHERS             = 3.
        IF sy-subrc <>  0.
*        RETCODE = 2.
        ELSE.

          LOOP AT lt_texts INTO DATA(ls_text).
		"Here The HTML body is with customer data.		
          ENDLOOP.

        ENDIF.

        c_length = i_length.

        CALL FUNCTION 'SCMS_STRING_TO_FTEXT'
          EXPORTING
           text      = body_str
          TABLES
            ftext_tab = lt_note.

        IF lt_note IS NOT INITIAL.
          TRY.
              io_send->send_request->setu_note( lt_note ). "The note is acting as the Email body
            CATCH cx_document_bcs cx_send_req_bcs.
          ENDTRY.
        ENDIF.

      ls_msg-msgv1 = ls_root-tor_id.
      SHIFT ls_msg-msgv1 LEFT DELETING LEADING '0'.
      DATA(lv_subj) = lo_easy_email->get_subj_from_kschl(
        iv_kschl = 'ZCON'
        iv_msgv1 = ls_msg-msgv1
        ).
      lv_subject = lv_subj.
      IF lv_subject IS NOT INITIAL.
        TRY.
            io_send->send_request->set_message_subject( lv_subject ).
          CATCH cx_document_bcs cx_send_req_bcs.
        ENDTRY.

      ENDIF.

      WHEN OTHERS.
    ENDCASE.

  ENDMETHOD.

 

 Now the Email is successfully triggered via the Freight order. But the first problem is we are seeing the Note along with the HTML tags:

Freight order-> Output Management tab:

jay_d_1-1715952506800.png

And when we check the Email in SOST, the body is also coming with the HTML tags instead of the format.

jay_d_3-1715952974258.png

Could anyone please help how can we send the formatted Email with PPF framework in SAP transportation management?

 

 

Ryan-Crosby
Active Contributor
0 Kudos
Where's the code for the creation of the document for the BCS request?

Accepted Solutions (0)

Answers (1)

Answers (1)

jay_d
Explorer
0 Kudos

Hi Ryan,

I tried using the following code to create the document instead of setting the note. But in this case, the email body is blank.

      IF lt_body IS NOT INITIAL.
          DATA(document) = cl_document_bcs=>create_document( i_type    = 'HTM' "'RAW'
                                                           i_text    = lt_note
                                                           i_length  = c_length
                                                           i_subject = CONV #( lv_subject ) ).
          TRY.
              io_send->send_request->setu_document( document ).
              io_send->send( i_with_error_screen = space ).
              CATCH cx_send_req_bcs. " BCS: Send Request Exceptions

            CATCH cx_document_bcs cx_send_req_bcs.
          ENDTRY.
      ENDIF.

 But setu_document( ) and setu_note( ) does not work together. I tried setting both together but it gives a dump.

Regards.

Ryan-Crosby
Active Contributor
0 Kudos
If you are using the i_text parameter you don't need to pass i_length. I would try again by removing that parameter because you should see text as long as lt_note has data.
jay_d
Explorer
0 Kudos

Hi Ryan,

Removing the length doesn't seem to resolve the issue.