Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 950

Re: Sending work item as attachment in Email (Outlook)

$
0
0

Hi, Siddhartha !

 

It's not easy to find out the exact reason why your function module doesn't work just because it is too complex (it seems to be a copy of RSWUWFML2 :-) ).

 

I can advice you the following:

 

1. Function modules such as SO_NEW_DOCUMENT_ATT_SEND... are too complex. It is recommended to use CL_BSC instead. Please refer to this wiki page.

 

2. There is a COMMIT WORK statement inside your function module. Both implicit and explicit commits are prohibited in workflow exits (link). May be it will be enough just to comment it out. Perhaps the process of the work item creation is not yet finished in the event AFTER_CREATE. Hence, you cannot properly use the ID of the work item which is not yet created.

 

3. I tried to create a test example using CL_BSC.

It works in my test system.

 

class ZCL_WF_EXIT_SEND_MAIL definition
   public
   final
   create public .

public section.

   interfaces IF_SWF_IFS_WORKITEM_EXIT .

   class-methods SEND_MAIL
     importing
       !IP_WI_ID type SWW_WIID .
   class-methods CREATE_ATTACHMENT
     importing
       !IP_WI_ID type SWW_WIID
     exporting
       !EPT_TABLE type SOLI_TAB .
protected section.
private section.
ENDCLASS.



CLASS ZCL_WF_EXIT_SEND_MAIL IMPLEMENTATION.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_WF_EXIT_SEND_MAIL=>CREATE_ATTACHMENT
* +-------------------------------------------------------------------------------------------------+
* | [--->] IP_WI_ID                       TYPE        SWW_WIID
* | [<---] EPT_TABLE                      TYPE        SOLI_TAB
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD create_attachment.
*
*- create sap shortcut attachment

*  entered( 'create_action_wa_attach' ).

   DATA: l_param    TYPE text255.
   DATA: l_logon_id TYPE text40.
   DATA: l_scrap    TYPE text255.


*- assemble the parameter string
   CONCATENATE
     'p_action=' 'DISPLAY'                                    "#EC NOTEXT
     '; p_wi_id=' ip_wi_id                             "#EC NOTEXT
     '; DYNP_OKCODE=ONLI'                                    "#EC NOTEXT
     INTO l_param.


*- create the shortcut as table
   CALL FUNCTION 'SWN_CREATE_SHORTCUT'
    EXPORTING
      i_transaction                 = '*swnwiex'             "#EC NOTEXT
      i_parameter                   = l_param
      i_sysid                       = sy-sysid
      i_user                        = sy-uname
      i_language                    = sy-langu
      i_windowsize                  = 'Normal window'        "#EC NOTEXT
      i_custom                      = l_scrap
    IMPORTING
      shortcut_table                = ept_table
*    SHORTCUT_STRING               =
    EXCEPTIONS
      OTHERS                        = 1.


ENDMETHOD.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_WF_EXIT_SEND_MAIL->IF_SWF_IFS_WORKITEM_EXIT~EVENT_RAISED
* +-------------------------------------------------------------------------------------------------+
* | [--->] IM_EVENT_NAME                  TYPE        SWW_EVTTYP
* | [--->] IM_WORKITEM_CONTEXT            TYPE REF TO IF_WAPI_WORKITEM_CONTEXT
* | [!CX!] CX_SWF_IFS_WORKITEM_EXIT_ERROR
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_swf_ifs_workitem_exit~event_raised.

   IF ( im_event_name = if_swf_ifs_workitem_exit~c_evttyp_after_create ).



     me->send_mail(
       ip_wi_id = im_workitem_context->get_workitem_id( )
     ).

   ENDIF.


ENDMETHOD.


* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_WF_EXIT_SEND_MAIL=>SEND_MAIL
* +-------------------------------------------------------------------------------------------------+
* | [--->] IP_WI_ID                       TYPE        SWW_WIID
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD send_mail.

   DATA:
     gv_mlrec         TYPE so_obj_nam,
     gv_sent_to_all   TYPE os_boolean,
     gv_email         TYPE adr6-smtp_addr,


     gv_subject       TYPE so_obj_des,
     gv_text          TYPE bcsy_text,
     gr_send_request  TYPE REF TO cl_bcs,
      gr_sender        TYPE REF TO cl_sapuser_bcs,

     gr_bcs_exception TYPE REF TO cx_bcs,
     gr_recipient     TYPE REF TO if_recipient_bcs,

     gr_document      TYPE REF TO cl_document_bcs.



   "Create send request
   gr_send_request = cl_bcs=>create_persistent( ).

   "Email FROM...
   gr_sender = cl_sapuser_bcs=>create( sy-uname ).
   "Add sender to send request
   CALL METHOD gr_send_request->set_sender
     EXPORTING
       i_sender = gr_sender.

   "Email TO...
   gv_email = '****@****.ru'.
   gr_recipient = cl_cam_address_bcs=>create_internet_address( gv_email ).
   "Add recipient to send request
   CALL METHOD gr_send_request->add_recipient
     EXPORTING
       i_recipient = gr_recipient
       i_express   = 'X'.

   "Email BODY
   APPEND 'Hello world! My first ABAP email!' TO gv_text.
   gr_document = cl_document_bcs=>create_document(
                   i_type    = 'RAW'
                   i_text    = gv_text
                   i_length  = '12'
                   i_subject = gv_subject ).


data: lt_attach type soli_tab.

   create_attachment(
     EXPORTING
       ip_wi_id = ip_wi_id
     IMPORTING
       ept_table  = lt_attach
   ).

   gr_document->add_attachment(
   i_attachment_subject = 'wi'
   i_attachment_type    = 'SAP'
   i_att_content_text = lt_attach
   ).

   "Add document to send request
   CALL METHOD gr_send_request->set_document( gr_document ).

   "Send email
   CALL METHOD gr_send_request->send(
     EXPORTING
       i_with_error_screen = 'X'
                             ).
   "Commit to send email
*  COMMIT WORK.


ENDMETHOD.


ENDCLASS.





Viewing all articles
Browse latest Browse all 950

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>