a month ago - last edited a month ago
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:
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:
And when we check the Email in SOST, the body is also coming with the HTML tags instead of the format.
Could anyone please help how can we send the formatted Email with PPF framework in SAP transportation management?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
11 | |
8 | |
7 | |
7 | |
6 | |
6 | |
6 | |
6 | |
6 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.