The blog talks about different ways to create email and notifications from the systems. I have been using these methods for doing the changes and thought to include it in a blog .
Please read through these to understand on different options on how to handle the business requirement of sending notifications/emails . This is specifically related to the SRM space but some of these are also relevant to ECC area.I have also included the technical objects and code samples for a better understanding of how I have implemented them.
Changing text in the task
One of the easy ways is to modify the task directly . This also updates text in the UWL item sent to the recipient. Also if its sent as email it gets modified there as well . For doing so follow the below steps:
Find from SWIA as to what is the task ID for the particular scenario.
Now find the corresponding details for the task In the PFTC_CHG
I have used vendor number this is coming from Container. To understand the field name and what to write you should switch the technical View on
Now i see that the field Vendor No which I need is coming from WI_OBJECT_ID >> VENDOR >> VendorNo can be seen in the incoming structure.
This I have now added to both my subject which is in basic data
For Email content go to the tab description.Click on the pencil icon which opens up an editor.
Now click on Add symbol option and enter the variable you would like to see in the email.
After doing the changes in the task don’t forget to refresh the buffer using Tcode SWU_OBUF.
This would now change/ create email notifications specific to the task.
2. Using BBP_ALERTING BADI
It checks the events you have configured in the config as below
IMG: Supplier Relationship Management -> SRM Server -> Cross-Application Basic Settings -> Event and Event Schema for Alert Management → Define Events
Here I am checking for events related to contract
I can see events like ‘APPROVAL_PROCESS_DOC_APPROVED’ and ‘APPROVAL_PROCESS_DOC_REJECTED’
In method method if_ex_bbp_alerting_badi~bbp_events_det_recipients based on running these standard events you could add your own logic to determine recipients.
if is_event-object_type = BUS2000113 and ( is_event-event = 'APPROVAL_PROCESS_DOC_APPROVED' or is_event-event = 'APPROVAL_PROCESS_DOC_REJECTED' ) and is_event-event_sub_categ = 'APPROVAL_RESULT_NOTIFIC_NEW' and is_event-event_categ = c_notification. call method custom_code_for_recipents ( exporting is_event = is_event changing ct_recipients = ct_recipients ).
If your requirement does not get met by using the standard config provided by SAP then use this BADI to read custom events and trigger notifications based on that . OR to change standard recipients etc.
The below link has a detailed documentation on this BADI.
- There is another method in this BADI which is IF_EX_BBP_ALERTING_BADI~BBP_EVENTS_DET_CLASS_NAME
This calls the standard class CL_BBP_MESSAGE_CREATE so you could replace the class by copying this class and then redefine the method DETERMINE_TEXT . It carries the details of what needs to be sent in the notification. See the sample code as below:
IF iv_object_type = BUS2201. IF is_event-event = 'WF_APPR_LATEST_START' OR is_event-event = 'WF_COMPL_LATEST_START' MOVE 'ZCL_BBP_MESSAGE_CREATE' TO cv_class_name. ENDIF. ENDIF.
Now in this Zclass I have changed the code for determine text to read text according to client’s requirement.
3 ALRTCATDEF : I am honestly not sure why SAP gave so many options for doing the same thing in multiple ways. So based on my understanding this one was probably for Functional people where they can configure alerts and edit the text and define priority etc based on how we just did using a BADI.
So here you can check for the SRM alerts section and in that I am using the BO as Purchase order in the right side.
Based on the specific criteria like a particular event or a specific value of ABAP field you can configure when the notification should be sent . The actual text to be sent goes in ‘Long and short text’ tab and also you could set priority for the message from the ‘properties’ tab.
Use report RSALERTTEST to test the approval alert configuration. Below document has good information around what needs to be included
3. Another BADI which is often used in SRM to send notifications is BBP_OFFLINE_APP_BADI
This is used for sending notifications for the work items which are pending approval by the users.
This BADI is actually called in the standard SRM report /SAPSRM/OFFLINEAPPROVALSEND
And in this BADI you have methods which can be used to customize what gets sent to the user.
Method RECIPIENTS_GET to see if managers needs to be marked for a particular kind of email.
Method WORKITEMS_SELECT to select a specific task which was for buyers
Method MAIL_DATA_GET : Read your custom text in this method
Method MAIL_CREATE : lets you send attachment, Change subject, Body of the email
There is a parameter in MAIL_DATA_GET method called as is_sel_params-one4all = ‘X’ this sends one email per approver
“There are two types of sending of the mail: “One mail per workitem” and “One message for user”.
The code checks the variable s_opt-one4all, when it is set then the “One message for user” is used”
Read the below links for a detailed documentation on the BADI.
4. Modifying Attachments sent as SMARTFORMS.
BADI BBP_OUTPUT_CHANGE_SF is used to change the standard form names to your custom smarform with customer’s branding and logo.
This is called when a user clicks on a print/ Print preview button on the PO and the SC.
However you may call the implementation of this BADI if you plan to send attachments with your emails
The code for this BADI is something as below where I am forcing my smartform name based on some condition like object type and process type which is the document type
Also if you notice below I changed the format of the email from RAW to HTM
* find the alternative form SELECT SINGLE formname formname_mail INTO (lv_formname, lv_formname_email) FROM ztest WHERE custom_type = lv_process_type. IF lv_formname IS INITIAL. MOVE lv_formname TO cv_smartform. ENDIF. IF lv_formname_email IS NOT INITIAL. MOVE lv_formname_email TO cv_smartform_mail. MOVE 'HTM' TO cs_parameters-mail_format. ENDIF.
I hope I was able to throw some light (rather than confusing more) on different ways on how I have handled clients requirement to modify notifications and emails as per the business requirement.
Thanks for taking time to read my blog and please let me know if any queries / comments.