I am trying to attach a document to a CRM Notification from application Web Dynpro for ABAP, I have build a FM that includes the method
cl_crm_documents=>create_with_file
When I test the FM from SE37 transaction, I am able to attach a file from a local disk succesfully. But If I call this FM from Web Dynpro, trying to do the same operation, document cannot attach to notification and Method returns the following error: Error loading file (Class of message CRM_DOCUMENTS and number 100).
Thanks in advance.
FUNCTION z_crm_anexar_docs_inc.
*"----
-
""Interfase local
*" IMPORTING
*" VALUE(GUID) TYPE CRMT_OBJECT_GUID
*" VALUE(FILENAME) TYPE SDOK_FILNM
*" VALUE(PATH) TYPE SDOK_CHTRD OPTIONAL
*" VALUE(DESCRIPTION) TYPE STRING
*"----
-
DATA: ls_bor TYPE sibflporb,
lv_loio TYPE skwf_io,
lv_phio TYPE skwf_io,
lv_error TYPE skwf_error.
MOVE: 'BUS2000116' TO ls_bor-typeid, "aqui le pasamos el tipo de objeto que estemos tratando
'BO' TO ls_bor-catid,
guid TO ls_bor-instid.
DATA: wa_result_tab TYPE string.
DATA: result_tab TYPE STANDARD TABLE OF string.
DATA: lin TYPE i.
DATA: long_nombre TYPE i.
DATA: long_total TYPE i.
DATA: desplazamiento TYPE i.
DATA: filename_aux TYPE skwf_descr.
SPLIT filename AT '' INTO TABLE result_tab.
DESCRIBE TABLE result_tab LINES lin.
READ TABLE result_tab INDEX lin INTO wa_result_tab.
IF sy-subrc EQ 0.
long_total = STRLEN( filename ).
long_nombre = STRLEN( wa_result_tab ).
desplazamiento = long_total - long_nombre.
path = filename(desplazamiento).
filename = wa_result_tab.
filename_aux = wa_result_tab.
ENDIF.
aqui le pasamos el guid del documento sap crm que estemos tratando
CALL METHOD cl_crm_documents=>create_with_file
EXPORTING
aqui le pasamos el nombre del fichero que queremos anexar
file_name = filename
'c:' "aqui le pasamos la ruta del fichero que queremos anexar
directory = path
business_object = ls_bor
IMPORTING
loio = lv_loio
phio = lv_phio
error = lv_error.
aqui llamamos a este método porque de lo contrario el sistema crea el anexo con el nombre que
le da la gana y no con el que hemos indicado en el punto anterior. por eso renombramos el fichero
CALL METHOD cl_crm_documents=>rename_object
EXPORTING
is_io = lv_loio
iv_name = filename_aux.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
IMPORTING
RETURN =
ENDFUNCTION.
Call from WDA.
CALL FUNCTION 'Z_CRM_ANEXAR_DOCS_INC'
EXPORTING
guid = guid_jarcode
guid = stru_importing-guid
filename = stru_importing-filename
PATH =
description = stru_importing-description.
ENDMETHOD.
Thanks in advance.