Attachment to Business Partner or Product in CRM
Great blog by Bhanu chander .
***********************************************************************
** Data Declarations **
***********************************************************************
DATA: li_bor TYPE sibflporb,
li_prop TYPE sdokproptys,
lwa_prop TYPE sdokpropty,
li_file_access_info TYPE sdokfilacis,
lwa_file_access_info TYPE sdokfilaci,
lv_loio TYPE skwf_io,
lv_phio TYPE skwf_io,
lv_error TYPE skwf_error,
i_text TYPE TABLE OF sdokcntbin,
ls_folder TYPE skwf_io,
t_requ TYPE crm_kw_propst,
t_propvalue TYPE TABLE OF sdokproptl,
wa_propvalue TYPE sdokproptl,
wa_requ TYPE crm_kw_props
lv_folder TYPE skwf_ios.
***********************************************************************
** Filling required fields **
***********************************************************************
***Business Object
li_bor-typeid = 'BUS1006' (Business Partner)
'BUS1178' (Product)
li_bor-catid = 'BO'.
li_bor-instid = partner guid. (Business partner /Product)
***FileName
lwa_prop-name = 'KW_RELATIVE_URL'.
lwa_prop-value = File Name. (e.g.: EXCEL1.xlsx)
APPEND lwa_prop TO li_prop.
***Description
lwa_prop-name = 'DESCRIPTION'.
lwa_prop-value = Attachment Description (e.g.: Excel).
APPEND lwa_prop TO li_prop.
***Language
lwa_prop-name = 'LANGUAGE'.
lwa_prop-value = sy-langu. (Language in which attachment is loaded)
APPEND lwa_prop TO li_prop.
***Assign file properties
CLEAR: lwa_file_access_info.
lwa_file_access_info-file_size = Size of attachment on Application server.
lwa_file_access_info-binary_flg = 'X'.
lwa_file_access_info-first_line = 1.
lwa_file_access_info-file_name = Absolute file path on Appication server.
lwa_file_access_info-mimetype = Internal File type extension
lwa_file_access_info-property = File Extension.
APPEND lwa_file_access_info TO li_file_access_info.
***********************************************************************
** Required for PRODUCT Attachment for FOLDER IDENTIFICATION **
***********************************************************************
CALL METHOD cl_crm_documents=>get_info_for_folder
EXPORTING
business_object = li_bor
** properties_request = query
* properties_query =
IMPORTING
properties_result = t_requ
folders = lv_folder.
LOOP AT t_requ INTO wa_requ.
t_propvalue[] = wa_requ-properties[].
READ TABLE t_propvalue INTO wa_propvalue
WITH KEY name = 'KW_RELATIVE_URL'
value = 'THUMBNAILS'.
IF sy-subrc = 0.
ls_folder-objtype = wa_requ-objtype.
ls_folder-class = wa_requ-class.
ls_folder-objid = wa_requ-objid.
CONTINUE.
ENDIF.
ENDLOOP.
***********************************************************************
** Create Attachment in Document Tab **
***********************************************************************
CALL METHOD cl_crm_documents=>create_with_table
EXPORTING
business_object = li_bor
properties = li_prop
file_access_info = li_file_access_info
file_content_binary = i_text[] "Binary file of Attachment from Application server
parent_folder = ls_folder "Required for Product attachment
raw_mode = 'X'
IMPORTING
loio = lv_loio
phio = lv_phio
error = lv_error.
***********************************************************************
** Data Declarations **
***********************************************************************
DATA: li_bor TYPE sibflporb,
li_prop TYPE sdokproptys,
lwa_prop TYPE sdokpropty,
li_file_access_info TYPE sdokfilacis,
lwa_file_access_info TYPE sdokfilaci,
lv_loio TYPE skwf_io,
lv_phio TYPE skwf_io,
lv_error TYPE skwf_error,
i_text TYPE TABLE OF sdokcntbin,
ls_folder TYPE skwf_io,
t_requ TYPE crm_kw_propst,
t_propvalue TYPE TABLE OF sdokproptl,
wa_propvalue TYPE sdokproptl,
wa_requ TYPE crm_kw_props
lv_folder TYPE skwf_ios.
***********************************************************************
** Filling required fields **
***********************************************************************
***Business Object
li_bor-typeid = 'BUS1006' (Business Partner)
'BUS1178' (Product)
li_bor-catid = 'BO'.
li_bor-instid = partner guid. (Business partner /Product)
***FileName
lwa_prop-name = 'KW_RELATIVE_URL'.
lwa_prop-value = File Name. (e.g.: EXCEL1.xlsx)
APPEND lwa_prop TO li_prop.
***Description
lwa_prop-name = 'DESCRIPTION'.
lwa_prop-value = Attachment Description (e.g.: Excel).
APPEND lwa_prop TO li_prop.
***Language
lwa_prop-name = 'LANGUAGE'.
lwa_prop-value = sy-langu. (Language in which attachment is loaded)
APPEND lwa_prop TO li_prop.
***Assign file properties
CLEAR: lwa_file_access_info.
lwa_file_access_info-file_size = Size of attachment on Application server.
lwa_file_access_info-binary_flg = 'X'.
lwa_file_access_info-first_line = 1.
lwa_file_access_info-file_name = Absolute file path on Appication server.
lwa_file_access_info-mimetype = Internal File type extension
lwa_file_access_info-property = File Extension.
APPEND lwa_file_access_info TO li_file_access_info.
***********************************************************************
** Required for PRODUCT Attachment for FOLDER IDENTIFICATION **
***********************************************************************
CALL METHOD cl_crm_documents=>get_info_for_folder
EXPORTING
business_object = li_bor
** properties_request = query
* properties_query =
IMPORTING
properties_result = t_requ
folders = lv_folder.
LOOP AT t_requ INTO wa_requ.
t_propvalue[] = wa_requ-properties[].
READ TABLE t_propvalue INTO wa_propvalue
WITH KEY name = 'KW_RELATIVE_URL'
value = 'THUMBNAILS'.
IF sy-subrc = 0.
ls_folder-objtype = wa_requ-objtype.
ls_folder-class = wa_requ-class.
ls_folder-objid = wa_requ-objid.
CONTINUE.
ENDIF.
ENDLOOP.
***********************************************************************
** Create Attachment in Document Tab **
***********************************************************************
CALL METHOD cl_crm_documents=>create_with_table
EXPORTING
business_object = li_bor
properties = li_prop
file_access_info = li_file_access_info
file_content_binary = i_text[] "Binary file of Attachment from Application server
parent_folder = ls_folder "Required for Product attachment
raw_mode = 'X'
IMPORTING
loio = lv_loio
phio = lv_phio
error = lv_error.
Post a Comment