METHOD if_ex_solar_documents~save_document. *********************************************************************** * Change history: * 1.00 05.06.12 Suchy, Monika * ************************************************************************
* Data definitions ************************************************************************ * DATA: l_text TYPE soli_tab, l_header TYPE so_obj_des, l_recipient TYPE ad_smtpadr, l_subject TYPE so_obj_des, iwb_description TYPE sdokpropty-value, iwb_tech_name TYPE sdokpropty-value, iwb_state TYPE sdokpropty-value, iwb_solar_docutype TYPE sdokpropty-value, iwb_solar_prio TYPE sdokpropty-value, iwb_responsible TYPE sdokpropty-value, iwb_folder_id TYPE sdokpropty-value, iwb_p_description TYPE sdokpropty-value, iwb_p_tech_name TYPE sdokpropty-value, iwb_p_state TYPE sdokpropty-value, iwb_p_solar_docutype TYPE sdokpropty-value, iwb_p_solar_prio TYPE sdokpropty-value, iwb_p_responsible TYPE sdokpropty-value, l_string TYPE string, lo_recipient TYPE REF TO if_recipient_bcs, lo_send_request TYPE REF TO cl_bcs, lo_document TYPE REF TO cl_document_bcs, ls_current_attrib TYPE LINE OF sdokproptys, ls_previous_attrib TYPE LINE OF sdokproptys, sent_to_all, lx_document_bcs TYPE REF TO cx_root.
***************************************************************** * Recipient l_recipient = ‘test@test.de’. *Subject l_subject = ‘SolMan: Status change Doc ‘.
*Get attributes LOOP AT it_current_attributes INTO ls_current_attrib.
CASE ls_current_attrib-name. WHEN ‘DESCRIPTION’. iwb_description = ls_current_attrib-value. WHEN ‘IWB_TECH_NAME’. iwb_tech_name = ls_current_attrib-value. WHEN ‘IWB_STATE’. iwb_state = ls_current_attrib-value. WHEN ‘IWB_SOLAR_DOCUTYPE’. iwb_solar_docutype = ls_current_attrib-value. WHEN ‘IWB_SOLAR_PRIO’. iwb_solar_prio = ls_current_attrib-value. WHEN ‘IWB_RESPONSIBLE’. iwb_responsible = ls_current_attrib-value. WHEN ‘IWB_FOLDER_ID’. iwb_folder_id = ls_current_attrib-value. ENDCASE. ENDLOOP.
LOOP AT it_previous_attributes INTO ls_previous_attrib. CASE ls_previous_attrib-name. WHEN ‘DESCRIPTION’. iwb_p_description = ls_previous_attrib-value. WHEN ‘IWB_TECH_NAME’. iwb_p_tech_name = ls_previous_attrib-value. WHEN ‘IWB_STATE’. iwb_p_state = ls_previous_attrib-value. WHEN ‘IWB_SOLAR_DOCUTYPE’. iwb_p_solar_docutype = ls_previous_attrib-value. WHEN ‘IWB_SOLAR_PRIO’. iwb_p_solar_prio = ls_previous_attrib-value. WHEN ‘IWB_RESPONSIBLE’. iwb_p_responsible = ls_previous_attrib-value. ENDCASE. ENDLOOP.
*e-mail text CONCATENATE ‘Document: ‘ iwb_description INTO l_string. APPEND l_string TO l_text. CONCATENATE ‘Project: ‘ i_project_id INTO l_string. APPEND l_string TO l_text. CONCATENATE ‘Solution: ‘ i_solution_id INTO l_string. APPEND l_string TO l_text. CONCATENATE ‘Status new: ‘ iwb_state INTO l_string. APPEND l_string TO l_text. CONCATENATE ‘Status old: ‘ iwb_p_state INTO l_string. APPEND l_string TO l_text. CONCATENATE ‘Responsible: ‘ iwb_responsible INTO l_string. APPEND l_string TO l_text. APPEND ” TO l_text. APPEND ‘Your Solution Manager’ TO l_text.
*check status change IF iwb_state NE iwb_p_state. IF iwb_state = ‘REVIEW’.
TRY. lo_document = cl_document_bcs=>create_document( i_type = ‘RAW’ i_text = l_text i_subject = l_subject ).
CATCH cx_document_bcs INTO lx_document_bcs. “ * error handling ENDTRY.
*Now create the e-mail
TRY. lo_send_request = cl_bcs=>create_persistent( ). lo_send_request->set_expires_on( ‘199901010000’ ). lo_send_request->set_document( lo_document ).
* Recipient
TRY. lo_recipient = cl_cam_address_bcs=>create_internet_address( i_address_string = l_recipient ).
lo_send_request->add_recipient( EXPORTING i_recipient = lo_recipient i_express = ‘X’).
CATCH cx_address_bcs INTO lx_document_bcs. * error handling ENDTRY.
* Send lo_send_request->send( EXPORTING i_with_error_screen = ‘X’ RECEIVING result = sent_to_all ).
IF sent_to_all <> ‘X’. lo_send_request->delete( ). ENDIF.
CATCH cx_send_req_bcs INTO lx_document_bcs. * error handling ENDTRY.
COMMIT WORK.
ENDIF. ENDIF.
ENDMETHOD.
|
Monika, very good post.
Follow your turorial but the email is not being sent.
Another thing, is there any way to send email to the user that the document included?
It would be much more useful the user who created the document in solar02 receive email and not who changed the status.
please check, if your general email settings are correct. For testing this, you can send an email via system --> short message (enter a valid email address)
In the next step check SOST