cancel
Showing results for 
Search instead for 
Did you mean: 

Attaching email(.msg) to a service request

faisal_pc
Active Contributor
0 Kudos

Hi Friends,

I have a requirement to attach the email message-which has come as an inbound email to CRM-in the service request. I mean, first I will click on email, then will press on service request. This will create a service request for the sender of email. Now, I need the inbound email in the attachment section of the newly getting created service request. Could anyone help me with a sample code?.

Note: I am not looking for how to attach the attachments in the email to the service request. I need the message as a whole in either .msg format or in PDF format.

Thanks,

Faisal

Accepted Solutions (0)

Answers (2)

Answers (2)

faisal_pc
Active Contributor
0 Kudos

Hi All,

Any pointers?.

Thanks,

Faisal

Former Member
0 Kudos

Hi Faisal,

How are you ?  Hope you remember me.. if not i am your batch mate in accenture..:D

Here is the code for attaching any file(.MSG worked for me).

in order to get  email data , I really dont know.. i only giving the second part attaching email to the service request..Just a sudo code.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

            EXPORTING

              input  = gs_crm_ids-object_id

            IMPORTING

              output = gs_crm_ids-object_id.

*      *     Assign business object

          ls_business_object-instid  = gs_crm_ids-guid."Header GUID

          ls_business_object-typeid  = 'BUS2000116'.

          ls_business_object-catid   = 'BO'.

*Delete the old document

* call method get_info of class cl_crm_documents so as to get the

* attachment details barco ticket and import the properties_result, loios and phios

          CALL METHOD cl_crm_documents=>get_info

            EXPORTING

              business_object       = ls_business_object

            IMPORTING

              phioloios             = lt_phiolois

              ios_properties_result = lt_prop_result

              loios                 = lt_loio

              phios                 = lt_phio.

          LOOP AT  gt_attach INTO gs_attach WHERE extref = gs_searchkey-extref AND text IS NOT INITIAL.

*Refresh the  variables

            REFRESH : lt_properties,lt_file_access_info,lt_loiod,lt_bad,lt_data.

            CLEAR : ls_error,lv_full_name,lv_actual,ls_file_access_info,ls_error_e.

            SPLIT gs_attach-text AT '"' INTO lv_text1 lv_attachname lv_text2.

            REPLACE FIRST OCCURRENCE OF ',' IN lv_text1 WITH '#'.

            CONCATENATE p_path_d '\' lv_text1 lv_attachname INTO lv_pres_file.

            OPEN DATASET lv_pres_file FOR INPUT IN LEGACY BINARY MODE.

*OPEN DATASET lv_pres_file FOR INPUT MESSAGE lv_msg IN LEGACY BINARY MODE.

            IF sy-subrc IS NOT INITIAL.

              CLEAR gs_log_msg.

              gs_log_msg-extref    =  gs_attach-extref.

              gs_log_msg-doc_no    = gs_crm_ids-object_id.

              gs_log_msg-doc_guid  = gs_crm_ids-guid.

              CONCATENATE 'Unable to open the file ' lv_pres_file INTO gs_log_msg-msg SEPARATED BY space.

              APPEND gs_log_msg TO   gt_log_msg.

              gs_log_msg-msg = lv_msg .

              APPEND gs_log_msg TO   gt_log_msg.

              CLOSE DATASET lv_pres_file.

              CONTINUE.

            ELSE.

              DO.

                READ DATASET lv_pres_file INTO lv_xstring ACTUAL LENGTH lv_actual_l.

                IF sy-subrc <> 0.

                  EXIT.

                ELSE.

                  REFRESH :lt_data.

                  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

                    EXPORTING

                      buffer          = lv_xstring

                      append_to_table = 'LT_DATA'

                    IMPORTING

                      output_length   = lv_length_x

                    TABLES

                      binary_tab      = lt_data.

                  lv_actual = lv_actual + lv_actual_l .

                ENDIF.

              ENDDO.

              CLOSE DATASET lv_pres_file.

            ENDIF.

*meeka end comment

            lv_length  = lv_actual.

            IF lv_length > 0.

              lv_filepath =  lv_attachname."lv_pres_file.

              lv_file_size =  lv_length.

* Split the file path

              CALL FUNCTION 'CRM_KW_SPLIT_FILENAME'

                EXPORTING

                  iv_path      = lv_filepath

                IMPORTING

                  ev_filename  = lv_filename

                  ev_extension = lv_fileext

                  ev_mimetype  = lv_content_type.

              IF lv_content_type = 'application/octet-stream'."

                lv_file_type = lv_fileext.

                CALL FUNCTION 'SDOK_MIMETYPE_GET'

                  EXPORTING

                    extension            = lv_file_type

                    x_use_local_registry = 'X'

                  IMPORTING

                    mimetype             = lv_content_type.

              ENDIF.                                          "end Of Add by meeka

              CONCATENATE   lv_filename lv_fileext

                            INTO lv_file

                            SEPARATED BY '.'.

              CONCATENATE lv_filename lv_fileext INTO lv_full_name SEPARATED BY '.'.

*From the table lt_prop_result move the logical ios of files with same

* as lv_file_name to separate table LT_LOIOD and initialize a flag to

* indicate deletion of that file

              SORT lt_loio BY objid objtype.

              LOOP AT lt_prop_result INTO ls_result.

                READ TABLE lt_loio INTO ls_io WITH KEY objid = ls_result-objid

                                                        objtype = 'L'.

                IF sy-subrc IS INITIAL.

                  lt_prop = ls_result-properties.

                  SORT lt_prop BY name.

                  READ TABLE lt_prop INTO ls_prop WITH KEY name = lc_name."KW_RELATIVE_URL

                  IF sy-subrc IS INITIAL.

                    IF ls_prop-value = lv_full_name.

                      lv1_flag = gc_x.

                      APPEND ls_io TO lt_loiod_d.

                      CLEAR ls_io.

                    ENDIF.

                  ENDIF.

                ENDIF.

                CLEAR ls_result.

              ENDLOOP.

              lv_filename                = lv_full_name.

              ls_properties-name         = 'KW_RELATIVE_URL'.

              ls_properties-value        = lv_filename.

              APPEND ls_properties TO lt_properties.

              ls_properties-name         = 'LANGUAGE'.

              ls_properties-value        = sy-langu.

              APPEND ls_properties TO lt_properties.

              ls_properties-name         = 'DESCRIPTION'.

              ls_properties-value        = lv_full_name.

              APPEND ls_properties TO lt_properties.

              DESCRIBE TABLE lt_data LINES ls_file_access_info-last_line.

              ls_file_access_info-first_line = '1'.

* Assign file properties

              ls_file_access_info-file_size  = lv_file_size.

              ls_file_access_info-binary_flg = 'X'.

              ls_file_access_info-file_name  = lv_file.

              ls_file_access_info-mimetype   = lv_content_type.

              ls_file_access_info-property   = lv_fileext.

              APPEND ls_file_access_info TO lt_file_access_info.

*Create a Document using class CL_CRM_DOCUMENTS

              CALL METHOD cl_crm_documents=>create_with_table

                EXPORTING

                  business_object     = ls_business_object

                  properties          = lt_properties

                  file_access_info    = lt_file_access_info

                  file_content_binary = lt_data

                  raw_mode            = 'X'

                IMPORTING

                  loio                = ls_loio

                  phio                = ls_phio

                  error               = ls_error.

* Populate status message

              IF ls_error IS INITIAL.

* Using the logical and physical id's, get the file location as an URL

                CALL METHOD cl_crm_documents=>get_with_url

                  EXPORTING

                    loio     = ls_loio

                    phio     = ls_phio

                    url_type = '2'

                  IMPORTING

                    error    = ls_error

                    url      = lv_url.

CALL METHOD cl_crm_documents=>delete

              EXPORTING

                business_object = ls_business_object

                ios             = lt_loiod_d

              IMPORTING

                bad_ios         = lt_bad

                error           = ls_error_e.

faisal_pc
Active Contributor
0 Kudos

Hi Lok,

Yes I remember you. .....Thanks for the reply.

However, I achieved this via converting the mail to a pdf as I didn't get any hints on this at that time.

Thanks,

Faisal

Former Member
0 Kudos

Hi Faisal,

Okey.

Answer might help some one on future..

For one more addition to my last post. I have added in two way

one is Open dataset to read from the application server (and i did the conversion to binary which was tricky at that time).

Second one is using front end . here i used following function to read the Email.

  CALL METHOD cl_gui_frontend_services=>gui_upload

              EXPORTING

                filename                = lv_pres_file

                filetype                = 'BIN'

              IMPORTING

                header                  = lv_xstring

                filelength              = lv_length

              CHANGING

                data_tab                = lt_content

Regards,

Logu

Saurabh_Kabra
Participant
0 Kudos


Hi Faisal,

Can you please chek below code:

DATA:

  gr_consumer_proxy     TYPE REF TO   (inbound proxy class),

  gr_proto_attachment   TYPE REF TO   if_wsprotocol_attachments,

  gr_attachment         TYPE REF TO   if_ai_attachment,

          CREATE OBJECT gr_consumer_proxy.

    gr_proto_attachment ?=

      gr_consumer_proxy->get_protocol( if_wsprotocol=>attachments ).  

   

    gr_attachment =

      gr_proto_attachment->get_attachment_from_binary(

                             data = gv_attachment_xstring

                             type = if_ai_attachment=>c_mimetype_pdf

                             name = 'AttachmentDocument' ).
   
APPEND gr_attachment TO gt_attachments.
    gr_proto_attachment->set_attachments( gt_attachments ).

Thanks

Saurabh

faisal_pc
Active Contributor
0 Kudos

Hi Saurabh,

I am not using any proxy. My requirement is just to attach the .msg file with service order. I have a call back function module where I have to write the code. Do you have some code snippets?

Thanks,

Faisal