Offline - External Mail Approval Process Without Using SAP Part-2
Offline - External Mail Approval Process Without Using SAP Part-2
Former Member
3 Kudos
9,931 Views
we are creating a very simple workflow template with a single User Decision Step. The template is shown (Notice there is no SEND MAIL step. E-Mail is sent via the Work Item exit)
The work item exit is mentioned in the user decision step as shown below
In the exit, we write our E-mail logic in the method AFTER_WI_CREATION. This method is triggered the moment the User Decision Work Item is created and sent to the
approver. Our E-mail is also created and sent almost at the same instant. The code in this method is shown. The system E-mail ID will depend on the ID created by your
infrastructure team.
(Note: I have shown two different ways to send the E-mail; one via the BCS Class and the other the SOFM Function Module. Please select whichever way you prefer. Remember to comment out one of
the ways, else you will get two E-mails on Work Item Creation)
METHOD after_wi_creation.
lv_lines TYPE i,
* For simplicity of the demo, we are only fetching the work item ID
* You can get the complete work item and workflow details as well
RECEIVING
re_workitem = lcl_v_wi_id.
* Pass WID to text field to concatenate to the e-mail body for MAILTO link
CLEAR: lv_wid_text.
lv_wid_text = lcl_v_wi_id.
REFRESH: l_it_father_wis[].
EXPORTING
wi_id = lcl_v_wi_id
TABLES
father_wis = l_it_father_wis.
* Read the Father WID, if not found then running WID is Father WID
* If Father Work Item ID found pass to the WID Variable else pass the Original WID
IF sy-subrc = 0.
lv_wid_read = l_wa_father_wis-wi_id.
ELSE.
lv_wid_read = lcl_v_wi_id.
ENDIF.
REFRESH: l_it_wi_container[].
CLEAR: l_wa_wi_header.
lv_wid_read = lcl_v_wi_id - 1.
EXPORTING
wi_id = lv_wid_read
TABLES
wi_container = l_it_wi_container
CHANGING
wi_header = l_wa_wi_header
EXCEPTIONS
container_does_not_exist = 1
read_failed =2
OTHERS = 3.
IF sy-subrc = 0.
CLEAR: l_wa_wi_container.
IF sy-subrc = 0.
CONDENSE l_wa_wi_container-value.
lv_bukrs = l_wa_wi_container-value.
ENDIF.
CLEAR: l_wa_wi_container.
IF sy-subrc = 0.
CONDENSE l_wa_wi_container-value.
lv_belnr = l_wa_wi_container-value.
ENDIF.
CLEAR: l_wa_wi_container.
IF sy-subrc = 0.
CONDENSE l_wa_wi_container-value.
lv_gjahr = l_wa_wi_container-value.
ENDIF.
CLEAR: l_wa_wi_container.
IF sy-subrc = 0.
CONDENSE l_wa_wi_container-value.
lv_email = l_wa_wi_container-value.
ENDIF.
ENDIF.
*----------------------------------------------------------------------------------------*
* Send an e-mail to a dummy e-mail ID stating that the above Work Item has been created
*----------------------------------------------------------------------------------------*
TRY.
send_request = cl_bcs=>create_persistent( ).
* CLEAR: body_text.
*--------------------------------------------------------------------*
CONCATENATE body_text
'<html><body>Dear User'
INTO body_text.
wa_message-line = body_text.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
INTO body_text.
wa_message-line = body_text.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<h4>Invoice Information</h4>'
INTO body_text.
wa_message-line = body_text.
CLEAR: wa_message.
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
CLEAR: body_text.
CONCATENATE body_text
INTO body_text.
wa_message-line = body_text.
CLEAR: body_text.
CONCATENATE body_text
'<tr><td>Invoice Number</td><td>'
lv_belnr
'</td></tr>'
INTO body_text.
CONDENSE body_text.
wa_message-line = body_text.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<tr><td>Company Code</td><td>'
lv_bukrs
'</td></tr>'
INTO body_text.
CONDENSE body_text.
wa_message-line = body_text.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<tr><td>Fiscal Year</td><td>'
lv_gjahr
'</td></tr>'
INTO body_text.
CONDENSE body_text.
APPEND body_text TO text.
wa_message-line = body_text.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
INTO body_text.
wa_message-line = body_text.
CLEAR: wa_message.
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
CLEAR: body_text.
CONCATENATE body_text
INTO body_text.
wa_message-line = body_text.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<tr>'
'<th>Header 1</th>'
'<th>Header 2</th>'
'<th>Header 3</th>'
'<th>Header 4</th>'
'<tr>'
'</tr>'
INTO body_text.
wa_message-line = body_text.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<tr>'
'</tr>'
INTO body_text.
wa_message-line = body_text.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<tr>'
'</tr>'
INTO body_text.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<tr>'
'</tr>'
'</table>'
INTO body_text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
CLEAR: body_text.
CONCATENATE body_text
INTO body_text.
wa_message-line = body_text.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'To approve the invoice via portal, please log onto the YOUR-COMPANY Business Portal by clicking here:'
INTO body_text.
wa_message-line = body_text.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
INTO body_text.
wa_message-line = body_text.
CLEAR: wa_message.
* Genrate the Dynamic MAILTO Links
CLEAR: body_text.
CONCATENATE body_text
'To process directly from e-mail, make your selection here '
INTO body_text.
wa_message-line = body_text.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<a href="mailto:[email protected]?subject=A'
lv_wid_text
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<a href="mailto:[email protected]?subject=R'
lv_wid_text
INTO body_text.
wa_message-line = body_text.
CLEAR: wa_message.
CONCATENATE body_text
'<br><h4>Please Note: The links will send an e-mail via MICROSOFT OUTLOOK.'
'Please do not change the subject, body or any information in that e-mail.</h4>'
INTO body_text.
wa_message-line = body_text.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
INTO body_text.
wa_message-line = body_text.
APPEND wa_message TO it_message.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'<span style="color:#FF0000">' "This is color for RED. Browser Safe colors mandatory to prevent broswer crash.
INTO body_text.
wa_message-line = body_text.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'For approval via e-mail, please click the links provided only. </h4></br>'
INTO body_text.
APPEND body_text TO text.
wa_message-line = body_text.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'</span>'
INTO body_text.
wa_message-line = body_text.
CLEAR: wa_message.
CLEAR: body_text.
CONCATENATE body_text
'</body></html>'
INTO body_text.
wa_message-line = body_text.
CLEAR: wa_message.
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
document = cl_document_bcs=>create_document(
i_length = lv_so_obj_len
EXPORTING
i_sender = sender.
EXPORTING
i_recipient = recipient
i_express = 'X'.
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = sent_to_all ).
* IF sent_to_all = 'X'.
* WRITE text-003.
* ENDIF.
COMMIT WORK.
* -----------------------------------------------------------
** exception handling
* -----------------------------------------------------------
* WRITE: text-001.
* EXIT.
ENDTRY.
*--------------------------------------------------------------------*
*--------------------------------------------------------------------*
CLEAR: w_doc_data.
w_doc_data-sensitivty = 'F'. "Fill the document data and get size of attachment
w_doc_data-obj_name = 'SAPRPT'.
CLEAR: wa_receivers.
REFRESH: t_receivers[].
wa_receivers-receiver = lv_email. "Get requestor mail id from table PA0105 based on his PERNR.
wa_receivers-rec_type = 'U'.
wa_receivers-com_type = 'INT'.
wa_receivers-notif_del = 'X'.
wa_receivers-notif_ndel = 'X'.
EXPORTING
document_data = w_doc_data
document_type = 'HTM' " To get the notification in HTML format
commit_work = 'X'
TABLES
object_content = it_message
receivers = t_receivers.
ENDMETHOD.
This completes our coding and configuration. We will now test our Workflow and see how it works in Part-3