Monday, December 28, 2020

SAP: How To Link Sent E-Mails to Business Objects

The so called 'Services for Object' are available for many central SAP objects, such as Purchase Orders, PM Notifications, Entry Sheets, etc. 


This post will focus on the function 'Services for Object -> Send -> Object Outbox'. 

The Object Outbox contains the E-Mails sent through the function 'Send object with note'.



The Object Outbox function displays the sent E-Mail as it is in the SOST transaction.

It is also possible to link E-Mails as services for the Business from customer specific business process and even from the message processing.

This post will discuss different ways of creating E-Mail Links depending on how the E-Mail is sent from the business process.

E-Mails sent through the function module 'SO_DOCUMENT_SEND_API1'

The approach of sending E-Mails through the function module 'SO_DOCUMENT_SEND_API1'  is obsolete but in case of enhancing an existing solution, there is a following way of linking the E-Mail from the business object:

We need to import the NEW_OBJECT_ID in our code. 


Throgh the method   get_bcs_obj_from_bci_key of the class cl_crm_email_utility_base we can retrieve the send request.

  CALL METHOD cl_crm_email_utility_base=>get_bcs_obj_from_bci_key
    EXPORTING
      is_bci_key          lv_new_object_id
    IMPORTING
      ev_send_request_bcs = data(lo_sendrequest).

Afterwards we can link the send request to the Business Object. 

lo_sendrequest->create_link( ls_borident ).

It is important to note that in this scenario we already have created the E-Mail send request and we create the Link to the Business Repository Object (BOR) in the next step.

The BORIDENT Structure is represented by the Object Type and the Object Key.
To make sure you have the right business object, you can refer to transaction SWO1. 

Example for entry sheets: Object Type BUS2091, object key is the fiels LBLINI from the table ESSR.

E-Mails sent through the Business Communication Service Class CL_BCS

The difference from the previous approach is that we link the E-Mail and the business object before the E-Mail was sent.

The BOR Object is linked to the request in the second step

* 1.Create persistent send request
      lx_send_request cl_bcs=>create_persistent).

* 2.Create Link between the Send Request and the BOR 
          CALL METHOD lx_send_request->create_link
            EXPORTING
              i_appl_object ls_borident
* 3.Send document
      CALL METHOD lx_send_request->send).


This is a very simple, clean code approach and recommended for new implementations or for enhancing functions that already use the Business Communication Service Class.

E-Mails that have already been sent from an Output Type as External Send

The NAST Table contains the E-Mail titles in the field TDCOVTITLE. 
Through the Title, you can find the SOOD record of the sent E-Mail.

The BOR Object and objekt key are also contained in the NAST Table (OBJTYPE, OBJKY), which makes it easy to link the mail.

Configuring  E-Mail Linking from Output Type 

Output types customized in the NACE transaction often send E-Mails, for example to customers or vendors. If the medium '5 - External Send' is used, the SAP Standard Logic (the parent program RSNASTSO) sends the mail through the function SO_OBJECT_SEND. 
Linking the E-Mail to the BOR Object is not easily possible.

If you use the medium '8 - Special Funktion', you can use the CL_BCS class.








2 comments:

  1. Hi Diana, could you provide some more information about the last part?

    ReplyDelete
    Replies
    1. Hello,

      as far as the last part is concerned, I think that you can use the Title of the mail from the customizing as a regex search and find the sent objects (e.g. Entry Sheets) from Table SOOD and then you can create the link like in step 1.

      I hope my explanation is understandable.

      Best Regards,
      Diana

      Delete