Skip to Content
Author's profile photo Former Member

Adobe Forms in WebUI

Purpose

To provide Print Preview with SAP Adobe forms of the any Business Transaction (here I have taken Service Contract)

PP1

 

 

 

 

 

 

 

 

 

 

Print & Print Preview is supported by SAP only for SAP Smartforms.  It’s  really strange for me why SAP does not have any standard approach for providing Adobe forms on WebUi, some how it works in SAPGUI.

 Adobe forms are more interactive and much intuitive and easy to create, modify, update forms.  It has slighe edge over smart forms. May be SAP will come up in future to support adobe forms in CRM webui. But as of CRM 7.0 EHP1 this is not available.

I did put up my own efforts to crack through this requirement and finally came up with impressive solution which is quiet easy to implement.

The actual SAP Smart form required Actions to be defined and implemented, where as in my approach of adobe forms action definitions are NOT required.

PP2

 

 Here we go…..

Steps in nutshell:

  1. Enhance the underlying Event Handler method of the Print Preview Button, UI Component BT112H_SC (service contract)
  2. Create a BSP ICF Service, similar to the standard print service CRM_PDF_PRINT, call it as ZCRM_PDF_PRINT
  3. In the even handler method (Step 1), construct the URL based on the Service defined in Step 2 and call the popup.
  4. Set up a Handler class for the service defined in Step 2, call it as ZCL_CRM_PREVIEW_PDF (Prototype CL_CRM_PREVIEW_PDF)
  5. In its handler method, call the method which is responsible to bring the pdf output in Xstring format.
  6. Set the pdf content to the response of the service with the application as ‘pdf’.

Let’s discuss the above steps in more detail fashion…..

1. Enhance Print Preview Button Event Handler method.

Enhance the UI Component BT112H_SC (Service Contract Header) in component Work Bench. Please choose your own component header according to the transaction type.

PP3_1

 

 

 

 

 

 

 

PP_3_2

 

 

 

 

 

 

 

 View & Event handler class are shown above.

2. Construct URL and Trigger POPUP window

Make use of method create_url in the class cl_crm_web_utility to construct URL

   concatenate 'scenario=P&guid=' lv_adminh_guid into lv_query.
* get URL
  lv_url = cl_crm_web_utility=>create_url(
            iv_path            = '/sap/crm/zcrm_pdf_print'
            iv_query           = lv_query
            iv_in_same_session = 'X' ).

 URL will have to set up in the ICF service, this we will see in further steps.  

 Create a popup with the help of window controller and make use of standard URL POPUP Interface View.

   lr_popup =  me->comp_controller->window_manager->create_popup(
          iv_interface_view_name = ‘GSURLPOPUP/MainWindow’
          iv_usage_name          = ‘CUGSURLPopup’
          iv_title               = lv_title ).

 Set the URL paramaters like Header_guid which will be retrived in the service handler class later.

lr_cn = lr_popup->get_context_node( ‘PARAMS’ ).

 Set up Popup configuration Settings like

  ls_params-url = lv_url.
  ls_params-height = ‘800’.
  ls_params-width = ‘800’.
  lr_obj->set_properties( ls_params ).
  lr_popup->set_display_mode( if_bsp_wd_popup=>c_display_mode_plain ).
  lr_popup->set_window_width( 820 ).
  lr_popup->set_window_height( 800 ).
  lr_popup->open( ).

 3. Define ICF Service for PDF PRINT PREVIEW.

 Now, it is required to define a custom  BSP ICF (Internet Communication Framework) Service.

 Tx: SICF 

Copy the standard ICF service for CRM_PDF_PRINT to the ZCRM_PDF_PRINT.

PP

 

 

 Define a Handler class to it like ZCL_CRM_PREVIEW_PDF, make of template method in standard class CL_CRM_PREVIEW_PDF

 PP6

 

 4. Populate the PDF data to the URL

 Now, we need to bring up the PDF data to populate as PDF Xstring and applicantion type as ‘pdf’, which will eventually open as PDF file in the popup.

 Method               IF_HTTP_EXTENSION~HANDLE_REQUEST

 Get the URL Params using the below method.

     ls_header_guid = server->request->get_form_field( ‘guid’ ).

 Now, the header_guid is available. Using the header_guid, we need to call a custom built method to bring the PDF Xstring data. I will show how to achieve this in next step.

      call method me->get_output_data
        exporting
          i_header_guid = ls_header_guid
        importing
          fpcontent     = lv_pdf_xstring.

 Get the length of the PDF String.
      call function ‘SCMS_XSTRING_TO_BINARY’
        exporting
          buffer        = lv_pdf_xstring
        importing
          output_length = lv_pdf_length
        tables
          binary_tab    = l_bin.

Define the application as PDF.

        lv_file_size = lv_pdf_length.
        lv_contenttype = ‘application/pdf’.
        ls_guid_str = ls_header_guid.
        concatenate ls_guid_str ‘.pdf’ into lv_filename.
        lv_file_name = lv_filename.

        server->response->append_data(
                            data   = lv_pdf_xstring
                            length = lv_pdf_length ).

 Set the response parameters

  concatenate ‘inline; filename=’ lv_filename
    into lv_contentdisposition.

  call method server->response->set_header_field
    exporting
      name  = ‘content-disposition’
      value = lv_contentdisposition.

  call method server->response->set_header_field
    exporting
      name  = ‘content-type’
      value = lv_contenttype.

  call method server->response->set_header_field
    exporting
      name  = ‘content-filename’
      value = lv_filename.

  server->response->delete_header_field(
           name = ‘Cache-Control’ ).                        “#EC NOTEXT

  server->response->delete_header_field(
           name = ‘Expires’ ).  

 5. Method: GET_OUTPUT_DATA to fetch the PDF DATA

 With Header guid, read all the Service contract information and pass on the same to the Adobe PDF Forms.

Get the Output parameters, most importantly, getpdf = X,

    fp_outputparams-nodialog      = ‘X’.
    fp_outputparams-getpdf      = ‘X’.
    fp_outputparams-preview      = ‘X’.

    call function ‘FP_JOB_OPEN’
      changing
        ie_outputparams = fp_outputparams
      exceptions
        cancel          = 1
        usage_error     = 2
        system_error    = 3
        internal_error  = 4
        others          = 5.

 Get the form related FM

          call function ‘FP_FUNCTION_MODULE_NAME’
            exporting
              i_name     = lv_formname
            importing
              e_funcname = fm_name.

Call the FM and export the form related data. This is usual way of calling Adobe forms. Output will not go to spool, rather it gives in XString format.  

 call function fm_name
        exporting
          /1bcdwb/docparams  = fp_docparams

        importing
          /1bcdwb/formoutput = fp_result.

 

Import the PDF XSTING DATA

fp_1 = fp_result-pdf.

IF it is required to attach more PDF forms to the same output file, then,

PP7

 

 Call multiple forms in desired order of sequence and attach the same using the following class:

   p_dest = cl_fp=>get_ads_connection( ).
* Get FP reference.
  l_fp = cl_fp=>get_reference( ).

*     Create PDF Object.
              l_pdfobj = l_fp->create_pdf_object( connection = p_dest ).

*     Set document.
              l_pdfobj->set_document( pdfdata = fp_out ).

 *     Set attachment.
              concatenate ‘Attachment’ sy-uzeit into l_attachment-name
                  separated by space.
            concatenate ‘Cover_letter’ ‘pdf’ into l_attachment-filename
                separated by ‘.’.
              l_attachment-mimetype    = ‘application/pdf’.
              l_attachment-description = l_attachment-name.
              l_attachment-data        = fp_2.
              insert l_attachment into table l_attachments.
              l_pdfobj->set_attachments( attachments = l_attachments ).

*     Execute, call ADS.
              l_pdfobj->execute( ).

*     Get result.
              l_pdfobj->get_document( importing pdfdata = fp_out ).

 Finally, export the PDF data in Xstring to the Handler method defined above.

Assigned Tags

      11 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member
      Please post me any questions or comments
      Author's profile photo Former Member
      Former Member
      Priya,

      In my scenario, I did not try interactive adode forms, its standalone ones. However, it should be possible if you designed forms in interactive way. Once the Pdf page comes up to the Webui, if the form is desgined interactive and there exists licensed Adobe life interactive form software (Please look for notes on Iteractive adobe forms), then it shud be possible to make interactive in webui.
      I never tried this before, So, i cannot give you more details on this.

      packages SFPT and SAFP will help you to play more with Adobe forms.

      Cheers, Satish

      Author's profile photo Former Member
      Former Member
      Hi satish,

      its  very fantastic blog.
      i have seen this http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/7089e001-fcd3-2b10-b08d-f36d78326c6e where emails can be sent from crm but there is no interaction between agent and form.

      In your blog, whether we can open the atatched form and change the content?
      my requirement is when we confirm the account with contact person, popup should come up with the email with the attached form.
      and the agent can open the form and change the content and even can chnage the email address.

      Please let me know how to achieve this

      Thanks,
      Priya

      Author's profile photo Former Member
      Former Member
      Nice blog!
      Author's profile photo Former Member
      Former Member
      In Step 2, You have mentioned below statement
      lr_obj->set_properties( ls_params ).

      But you have not mentioned the type of lr_obj. Can u please tell what is it?

      Regards,
      Amit

      Author's profile photo Roman Beketov
      Roman Beketov

      thanks a lot!!

      Author's profile photo Former Member
      Former Member

      Greetings Roman,

      following the document above,

      Get the form related FM

                call function 'FP_FUNCTION_MODULE_NAME'
                  exporting
                    i_name     = lv_formname
                  importing
                    e_funcname = fm_name.

      i have added the coding to get the form name as you said like below,

      lv_formname = server->request->get_form_field( 'form' ).

      but i get error as below,

      Kindly help on this , thanking you

      Author's profile photo Former Member
      Former Member

      Hi,

      I use above code and method but in that found one problem. If we call new component

        ls_params-url = lv_url.

        ls_params-height = '800'.

        ls_params-width = '800'.

        lr_obj->set_properties( ls_params ).

        lr_popup->set_display_mode( if_bsp_wd_popup=>c_display_mode_plain ).

        lr_popup->set_window_width( 820 ).

        lr_popup->set_window_height( 800 ).

        lr_popup->open( ).

      using above code its not opening new window in visible mode and pdf file is getting too small and nobody can see it.

      Can you please correct that?

      Cheers,

      Nainesh

      Author's profile photo Former Member
      Former Member

      Dear Satish,

      I tried implementing your solution. i am getting a blank page in popup.

      I followed the below steps:

      1. Created a new ICF service with my custom handler class.

      2. Instead of get_pdf, I called get_output_data; in the similar fashion as described in your blog. I could fetch the fpcontent as PDF content and then passed it back to Handler method.

      3. From Handler, I was able to set the server->response as suggested in the blog above.

      4. I am using my custom form which has got just one field as Opportunity description.

      Interestingly, when I test the form , I get the same situation i.e. blank page from tcode SFP as well.

      Please suggest.

      Regards,

      Vinamra.

      Author's profile photo Former Member
      Former Member

      Dear Satish,

       

      I found an issue regarding 'same origin policy' in browser. I created a popup like you said. It works fine in IE. But if in Chrome, it has problem after clicking the exit button. The busy indicator is always loading and never disappear. I found the root cause is Chrome thinks the popup window and the back end on_close() event are not at the same origin. IE is not that strict like Chrome, so it works fine.

      The workaround for Chrome is to open it by developer mode and close security check. I need your help, do you know any other way to solve this issue by coding?

       

      Regards,

      Angxiao

      Author's profile photo Srini Sandaka
      Srini Sandaka

      Hi Satish,

      Thanks for blog, it helped me a lot. But I am facing problem when I pass a context parameter as input to the Adobe form, it does not get the required PDF with data. My form is interactive. (I tried using same input in SFP and manually executed the form, there it works). But in Web ui popup I always get blank form, I checked the input is passed correctly. I am getting the value in the handler class and using that value i am calling the adobe form with this input value. The form is always blank, can you please suggest what might be wrong/missing.

      I am also not getting save or other options in the pop-up unlike your screen shot shows.

       

      Regards,

      Priya Raja