Attaching a Smartform in documents tab of contract using Actions

In our requirement we have to attach a smartform in documents tab of contract page.There is a method – CRM_GRM_GAGCONT_EXEC_SMARTFORM in standard class -CL_DOC_PROCESSING_CRM_ORDER , which can execute the smartform and attach the same in the one-order object.However the same cannot be used if the importing parameters of your smart form function module and the FM used in this method are different. In such a case you have to create your own custom method and class to achieve the requirement.I have detailed the steps below.

1)      First you have to create your own class with CL_SF_PROCESSING_PPF as superclass.

1.JPG

This will inherit a method – EXEC_SMART_FORM , which is used later to write your own method.

2)      Copy this method EXEC_SMART_FORM and paste as a new method.(this will copy all the attributes and source code of inherited method to your own method.) You can change the name of method if you wish to.

2.JPG


3)      Double click on the new method and copy the code as below : (You can copy the parameters from method EXEC_SMART_FORM )

* generally used constants of generic order
INCLUDE: crm_direct.

DATA:
control_parameters
TYPE ssfctrlop.

* file data
DATAls_fileinfo    TYPE sdokfilaci,
lt_fileinfo   
TYPE sdokfilacis,
lt_content_bin
TYPE sdokcntbins,                   “#EC NEEDED
lv_timestamp  
TYPE timestampl.

DATA: ls_output_info     TYPE  ssfcrescl.

* document error
DATAls_error       TYPE skwf_error.

* property data
DATA: ls_property    TYPE sdokpropty,
lt_properties 
TYPE sdokproptys,
ls_business_object
TYPE sibflporb,
lv_object_guid    
TYPE crmt_object_guid.

* function name
DATA: function_name TYPE rs38l_fnam,
dummy
(254)        TYPE c,
ls_archive_index 
TYPE toa_dara,
ls_orderadm_h    
TYPE crmt_output_orderadm_h_com,
ls_activity_h    
TYPE crmt_output_activity_h_com,
ls_opport_h      
TYPE crmt_output_opport_h_com,
ls_orgman_h      
TYPE crmt_output_orgman_h_com,
lt_partner_h     
TYPE crmt_output_partner_h_comt,
ls_pricingdata_h 
TYPE crmt_output_pricingdata_h_com,
ls_sales_h       
TYPE crmt_output_sales_h_com,
ls_shipping_h    
TYPE crmt_output_shipping_h_com,
lt_payplan_d_h   
TYPE crmt_output_payplan_d_h_comt,
ls_customer_h    
TYPE crmt_output_customer_h_com,
ls_cumulat_h    
TYPE crmt_output_cumulat_h_com,
lt_billing_h    
TYPE   crmt_output_billing_h_comt,
lt_cancel_h     
TYPE   crmt_output_cancel_h_comt,
lt_appointment_h
TYPE   crmt_output_appointment_h_comt,
lt_billplan_d_h 
TYPE   crmt_output_billplan_d_h_comt,
lt_billplan_h   
TYPE   crmt_output_billplan_h_comt,
lt_status_d_h   
TYPE   crmt_output_status_d_h_comt,
lt_status_h     
TYPE   crmt_output_status_h_comt,
lt_srv_subject_h
TYPE   crmt_output_srv_subject_h_comt,
lt_srv_reason_h 
TYPE   crmt_output_srv_reason_h_comt,
lt_srv_result_h 
TYPE   crmt_output_srv_result_h_comt,
ls_acs_h        
TYPE   crmt_acs_h_com,
lt_orderadm_i   
TYPE   crmt_output_orderadm_i_comt,
lt_orgman_i     
TYPE   crmt_output_orgman_i_comt,
lt_pricingdata_i
TYPE   crmt_output_pricingdata_i_comt,
lt_pricing_i    
TYPE   crmt_output_pricing_i_comt,
lt_product_i    
TYPE   crmt_output_product_i_comt,
lt_sales_i      
TYPE   crmt_output_sales_i_comt,
lt_shipping_i   
TYPE   crmt_output_shipping_i_comt,
lt_schedlin_i   
TYPE   crmt_output_schedlin_i_comt,
lt_customer_i   
TYPE   crmt_output_customer_i_comt,
lt_partner_i    
TYPE   crmt_output_partner_i_comt,
lt_item_cstics_i
TYPE   crmt_item_cstics_tab,
lt_billing_i    
TYPE   crmt_output_billing_i_comt,
lt_cancel_i     
TYPE   crmt_output_cancel_i_comt,
lt_finprod_i    
TYPE   crmt_output_finprod_i_comt,
lt_ordprp_i     
TYPE   crmt_output_ordprp_i_comt,
lt_appointment_i
TYPE   crmt_output_appointment_i_comt,
lt_billplan_d_i 
TYPE   crmt_output_billplan_d_i_comt,
lt_billplan_i   
TYPE   crmt_output_billplan_i_comt,
lt_orderadm_i_qt
TYPE   crmt_output_orderadm_i_qt_comt,
lt_orderadm_i_in
TYPE   crmt_output_orderadm_i_in_comt,
lt_schedlin_i_cf
TYPE   crmt_output_schedlin_i_cf_comt,
lt_status_i     
TYPE   crmt_output_status_i_comt,
lt_working_set_e_s_bbp
TYPE /1cn/working_set_e_s_bbp_t,
lv_language
LIKE  sylangu,
lo_order
TYPE REF TO cl_doc_crm_order,
lv_status
TYPE jstat,
lt_status
TYPE TABLE OF jstat,
lv_error_tab_wrk
TYPE ssferror,
ls_output_options
TYPE ssfcompop.

DATAlv_size    TYPE  i,
lv_pdf    
TYPE  xstring.

DATA  lt_contract_survey TYPE crmt_survey_api_contract_prnt2.
CONSTANTSlc_mimetype    TYPE w3conttype VALUE ‘application/pdf’.

* fill internal structure for the output options
ls_output_options
= is_output_options.

lo_order ?= io_appl_object.
lv_object_guid
= lo_order->get_crm_obj_guid( ).

* get the function name for this smart form
CALL FUNCTION ‘SSF_FUNCTION_MODULE_NAME’
EXPORTING
formname          
= ip_smart_form
IMPORTING
fm_name           
= function_name
EXCEPTIONS
no_form           
= 1
no_function_module
= 2
OTHERS             = 3.
IF sysubrc <> 0.
*   add an error message to processing protocol
MESSAGE i015(sppf_media) WITH ip_smart_form INTO dummy.
CALL METHOD cl_log_ppf=>add_message
EXPORTING
ip_problemclass
= ‘1’
ip_handle      
= ip_application_log.
EXIT.
ENDIF.

* determine the tables of the application
CALL FUNCTION ‘CRM_OUTPUT_SINGLE_READ’
EXPORTING
iv_object                
= io_appl_object
iv_smart_form            
= ip_smart_form
IMPORTING
es_output_orderadm_h     
= ls_orderadm_h
es_output_activity_h     
= ls_activity_h
es_output_opport_h       
= ls_opport_h
es_output_orgman_h       
= ls_orgman_h
es_output_pricingdata_h  
= ls_pricingdata_h
es_output_sales_h        
= ls_sales_h
es_output_shipping_h     
= ls_shipping_h
et_output_partner_h      
= lt_partner_h
et_output_payplan_d_h    
= lt_payplan_d_h
es_output_customer_h     
= ls_customer_h
es_output_cumulat_h      
= ls_cumulat_h
et_output_billing_h      
= lt_billing_h
et_output_cancel_h       
= lt_cancel_h
et_output_appointment_h  
= lt_appointment_h
et_output_billplan_d_h   
= lt_billplan_d_h
et_output_billplan_h     
= lt_billplan_h
et_output_status_d_h     
= lt_status_d_h
et_output_status_h       
= lt_status_h
et_output_srv_subject_h  
= lt_srv_subject_h
et_output_srv_reason_h   
= lt_srv_reason_h
et_output_srv_result_h   
= lt_srv_result_h
es_output_acs_h          
= ls_acs_h
et_output_orderadm_i     
= lt_orderadm_i
et_output_orgman_i       
= lt_orgman_i
et_output_pricingdata_i  
= lt_pricingdata_i
et_output_pricing_i      
= lt_pricing_i
et_output_product_i      
= lt_product_i
et_output_sales_i        
= lt_sales_i
et_output_shipping_i     
= lt_shipping_i
et_output_schedlin_i     
= lt_schedlin_i
et_output_partner_i      
= lt_partner_i
et_item_cstics_i         
= lt_item_cstics_i
et_output_customer_i     
= lt_customer_i
et_output_billing_i      
= lt_billing_i
et_output_cancel_i       
= lt_cancel_i
et_output_finprod_i      
= lt_finprod_i
et_output_ordprp_i       
= lt_ordprp_i
et_output_appointment_i  
= lt_appointment_i
et_output_billplan_d_i   
= lt_billplan_d_i
et_output_billplan_i     
= lt_billplan_i
et_output_orderadm_i_qt  
= lt_orderadm_i_qt
et_output_orderadm_i_in  
= lt_orderadm_i_in
et_output_schedlin_i_cf  
= lt_schedlin_i_cf
et_output_status_i       
= lt_status_i
et_output_wrk_set_e_s_bbp
= lt_working_set_e_s_bbp
ev_language              
= lv_language.

* fill the survey table.
CALL FUNCTION ‘CRM_CONTRACT_SURVEY_PRINT_TC’
EXPORTING
iv_header_guid       
= ls_orderadm_hguid
iv_language          
= lv_language
IMPORTING
et_survey_print_table
= lt_contract_survey.

* set mail title
SELECT SINGLE caption INTO ls_output_optionstdtitle
FROM stxfadmt WHERE
formname
= ip_smart_form AND
langu   
= lv_language.

IF ls_output_optionstdtitle  IS INITIAL.
SELECT SINGLE caption INTO ls_output_optionstdtitle
FROM stxfadmt WHERE
formname
= ip_smart_form.
ENDIF.

*CONCATENATE ‘ ‘ ‘&’ into ls_output_options-tdtitle.

*  ls_output_options = is_output_options.
*  ls_output_options-tdtitle = text-001.
REPLACE ‘&’ WITH ls_orderadm_hobject_id
INTO ls_output_optionstdtitle.

*———- is_mail_appl_obj ——————————————-
* fill this parameter if your application object is a BOR object
* the output will be connected with the BOR object via SAP Office
* this is done for mail and fax but not for print outputs
*   ——>
* is_mail_appl_obj-LOGSYS    =
* is_mail_appl_obj-OBJTYPE   =
* is_mail_appl_obj-OBJKEY    =
* is_mail_appl_obj-DESCRIBE  =
*   ——>
*———————————————————————–

*———–language of smart form————————————–
* determin here the language of the smart form
control_parameters
= is_control_parameters.
control_parameters
langu = lv_language.
control_parameters
GETOTF = ‘X’.
*———————————————————————–

*———–fill archive parameters for archive link ——————-
IF is_output_optionstdarmod = ‘2’ OR
is_output_options
tdarmod = ‘3’.
*   archive_index_tab
READ TABLE ct_archive_index_tab INTO ls_archive_index INDEX 1.
ls_archive_index
object_id      = ls_orderadm_hguid.
IF ls_archive_indexobject_id IS INITIAL.
DELETE ct_archive_index_tab INDEX 1.
ELSE.
MODIFY ct_archive_index_tab FROM ls_archive_index INDEX 1.
ENDIF.
ENDIF.
*———————————————————————–

* call function to process smart form
CALL FUNCTION function_name
EXPORTING
archive_index       
= is_archive_index
archive_index_tab   
= ct_archive_index_tab
archive_parameters  
= is_archive_parameters
control_parameters  
= control_parameters
mail_appl_obj       
= is_mail_appl_obj
mail_recipient      
= is_mail_recipient
mail_sender         
= is_mail_sender
output_options      
= ls_output_options
user_settings       
= ip_user_settings
orderadm_h          
= ls_orderadm_h
activity_h          
= ls_activity_h
opport_h            
= ls_opport_h
orgman_h            
= ls_orgman_h
partner_h           
= lt_partner_h
pricingdata_h       
= ls_pricingdata_h
sales_h             
= ls_sales_h
shipping_h          
= ls_shipping_h
payplan_d_h         
= lt_payplan_d_h
cumulat_h           
= ls_cumulat_h
customer_h          
= ls_customer_h
acs_h               
= ls_acs_h
billing_h           
= lt_billing_h
cancel_h            
= lt_cancel_h
appointment_h       
= lt_appointment_h
billplan_d_h        
= lt_billplan_d_h
billplan_h          
= lt_billplan_h
status_d_h          
= lt_status_d_h
status_h            
= lt_status_h
srv_subject_h       
= lt_srv_subject_h
srv_reason_h        
= lt_srv_reason_h
srv_result_h        
= lt_srv_result_h
orderadm_i          
= lt_orderadm_i
orderadm_i_qt       
= lt_orderadm_i_qt
orderadm_i_in       
= lt_orderadm_i_in
orgman_i            
= lt_orgman_i
pricingdata_i       
= lt_pricingdata_i
pricing_i           
= lt_pricing_i
product_i           
= lt_product_i
sales_i             
= lt_sales_i
schedlin_i          
= lt_schedlin_i
schedlin_i_cf       
= lt_schedlin_i_cf
shipping_i          
= lt_shipping_i
partner_i           
= lt_partner_i
item_cstics_i       
= lt_item_cstics_i
customer_i          
= lt_customer_i
billing_i           
= lt_billing_i
cancel_i            
= lt_cancel_i
finprod_i           
= lt_finprod_i
ordprp_i            
= lt_ordprp_i
appointment_i       
= lt_appointment_i
billplan_d_i        
= lt_billplan_d_i
billplan_i          
= lt_billplan_i
status_i            
= lt_status_i
working_set_e_s_bbp 
= lt_working_set_e_s_bbp
contract_main       
= lt_contract_survey
language             = lv_language
IMPORTING
document_output_info
= es_document_output_info
job_output_info     
= es_job_output_info
job_output_options  
= es_job_output_options
EXCEPTIONS
output_canceled     
= 1
parameter_error     
= 2
OTHERS               = 3.

* Generate OTF data
CALL METHOD cl_grm_gag_documents=>generate_otf_data
EXPORTING
lt_output_info
= es_job_output_infootfdata
IMPORTING
it_ev_size    
= lv_size
ev_pdf        
= lv_pdf.

*/Set file info and file content
ls_fileinfo
file_size  = lv_size.
ls_fileinfo
binary_flg = ‘X’.
ls_fileinfo
first_line = 1.
ls_fileinfo
file_name  = ‘contract1’.
ls_fileinfo
mimetype   = lc_mimetype.

*/Convert binary data
CALL FUNCTION ‘SCMS_XSTRING_TO_BINARY’
EXPORTING
buffer     = lv_pdf
TABLES
binary_tab
= lt_content_bin.

DESCRIBE TABLE lt_content_bin LINES ls_fileinfolast_line.

*/Get filename
IF ls_fileinfofile_name IS INITIAL.
GET TIME STAMP FIELD lv_timestamp.
ls_fileinfo
file_name = lv_timestamp.
SHIFT ls_fileinfofile_name LEFT DELETING LEADING space.
WRITE ls_fileinfofile_name+15(7) TO ls_fileinfofile_name+14.
CONCATENATE ls_fileinfofile_name ‘.pdf’ INTO ls_fileinfofile_name.
ENDIF.
APPEND ls_fileinfo TO lt_fileinfo.

*/Set properties (description & title)
ls_property
name  = skwfc_prop_description.

CALL METHOD cl_grm_gag_documents=>get_next_version_name
EXPORTING
iv_guid        
= lv_object_guid
iv_name        
= ls_fileinfofile_name
RECEIVING
rv_next_version
= ls_propertyvalue.

*  ls_property-value = cl_grm_gag_documents=>GET_NEXT_VERSION_NAME( lv_object_guid ).
APPEND ls_property TO lt_properties.
ls_property
name  = skwfc_prop_relative_url.

CALL METHOD cl_grm_gag_documents=>get_next_version_name
EXPORTING
iv_guid        
= lv_object_guid
iv_name        
= ls_fileinfofile_name
RECEIVING
rv_next_version
= ls_propertyvalue.

*  ls_property-value =  cl_grm_gag_documents=>GET_NEXT_VERSION_NAME( lv_object_guid ).
APPEND ls_property TO lt_properties.

ls_business_objectinstid = lv_object_guid.
ls_business_object
typeid = ‘BUS2000112’.
ls_business_object
catid  = ‘BO’.   “instance of BOR object type

** create document by using cl_crm_documents
CALL METHOD cl_crm_documents=>create_with_table
EXPORTING
business_object    
= ls_business_object
properties         
= lt_properties
file_access_info   
= lt_fileinfo
*     FILE_CONTENT_ASCII  =
file_content_binary
= lt_content_bin
raw_mode           
= ‘X’
*     TEXT_AS_STREAM      =
*     PARENT_FOLDER       =
IMPORTING
error              
= ls_error.
IF NOT ls_error IS INITIAL.
*    RAISE failed.
ENDIF.

4)      save and activate.

5)      Now you have to create your actions in action profile using below path :

SPRO->CRM->BASIC FUNCTION->ACTIONS->ACTIONS IN TRANSACTION->CREATE ACTION WITH WIZARD

6)      Wizard screen will open give the details as below or as per your needs

6.JPG


7)      I am using an existing action (You can create your action and assign it to the transaction for which you want the smartform to be attached.) Click on continue

8)      Give you are action definition name and description.

8.JPG

9)      Give processing time as “Processing when saving document” and check schedule automatically” if that is your requirement.

9.JPG

10)  Enter partner function for which you determination to happen. I have given sold to party – 00000001


10.JPG


11)  Now select the processing type as Smart Forms Print from the given options.

11.JPG

12)  Now comes the most important part. Here you have to give your smart form that you want to save, the class and method that we have created initially. This step links your code with the function settings of actions.

12.JPG

13)  Give Action description and navigate to complete.

13.JPG

14)  Schedule conditions and start conditions can be defined in the define conditions using path Actions->actions in transaction->change action and conditions->define condition

15)  Look for the action defined and double click. Here you can see your actions definition in right.

15.JPG

16)  Click on the schedule and start condition tabs to create your conditions. Shown below:

     i.e. action will start here when the above conditions are met.In my case when the contract is set to fully executed.

16.JPG

16b.JPG

17)  Now everything is done. We will check the output now.

18) log in to web ui and open the contract.

18.JPG

19) make the status fully executed ( for which the action has been scheduled) and save.

20) Eureka Eureka !!!!!!!!!!!! Document is attached in attachments block.

20.JPG

21) Click on the link and smart form will open in another tab.

21.JPG

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

Leave a Reply