How to load PDF from CRM Web UI or Interaction Center
Loading PDF document from CRM Web UI or Interaction center(IC) is a common use-case across different services. Here in this document we will go through all the steps involved in creating a PDF display from CRM UI/ IC.
There are two ways in which we can load the PDF:
- PDF URL
- PDF content using BSP page.
Loading PDF URL
The first option is the simplest, where you have URL for the PDF file and you would like to load it from Web UI. If the URL is static we can use a URL based transaction launcher and load in the UI. There are many articles available in SDN which talks about this topic so I will not elaborate on this. Alternatively, you can also load the URL’s using the get_p_<attr> method of the context node attribute. This approach will be useful in cases where the URL is dynamic. Again I am not going into the details as there are multiple documents published in SDN on this.
Loading PDF content
The second approach, loading the PDF content from web UI / IC is a common scenario in migration project. Let us take an example where the customer legacy system uses a third party archive tool for storing all the historical bills of customers. More often than not after migration, customers would like to retain the third party tool and just have a display view for those bills in CRM. Let us assume in this case the bills are stored in PDF form and the third party can send us the PDF content in the XSTRING format.
Below are the steps to load PDF on click of a hyperlink from the view.
Create a new controller Billdoc.pdf under your BSP component.
Now create a handler class and set it to the controller.
For the above created controller redefine do_request( ) method and set the response data. Let us assume in our case we are going to get PDF content through an RFC and below is the sample code for setting the response.
DATA: ebc_t_raw_data TYPE TABLE OF tbl1024,
xdata TYPE xstring.
*Get PDF content
CALL FUNCTION ‘ZGET_PDF_DOCUMENT’
im_opbel = lv_opbel
t_pdf_data = ebc_t_raw_data
t_return = return
communication_failure = 1
system_failure = 2
general_fault = 3
OTHERS = 4.
* Build xstring from itab format (dependent on itab type)
IF ebc_t_raw_data IS NOT INITIAL.
LOOP AT ebc_t_raw_data INTO ebc_line.
CONCATENATE xdata ebc_line–line INTO xdata IN BYTE MODE.
* Determine data length
size = xstrlen( xdata ).
* Export response data
CALL METHOD response->if_http_entity~append_data
data = xdata
length = size.
* Set response content-type as PDF
CALL METHOD response->if_http_entity~set_header_field
name = ‘content-type’ “#EC NOTEXT
value = ‘application/pdf’. “#EC NOTEXT
There are two key things to note in the above code:
Also note that we can play around with the content type to load different types of files.
And the last step is to load this BSP page on click of a hyperlink in the UI view.
Redefine get_p method and load the BSP page. Below is the sample code.
CALL METHOD cl_bsp_runtime=>get_runtime_instance
runtime = lr_runtime.
* create url using runtime
CALL METHOD lr_runtime->construct_bsp_url
in_application = ‘ZIUICINVOICE’ “BSP component name
in_page = ‘Billdocument.pdf’ “bsp controller created above
in_parameters = lt_params
out_local_url = rv_value.
Thus we are all set to load the PDF, click on the hyperlink and a new browser window containing PDF will be loaded. Below is the sample screen shot.
Very helpful, thank you.
But i have a question, how to pass value to the bsp controller Billdocument.pdf.
I see you use the input lt_params, can i read the inner table in the method
do_request( ) ?
thank you .
I find the solution. In the method do_request( ) use
request->get_form_field( 'fieldname' ) to get the value in lt_params, fieldname = lt_params-name.
I did all steps but it doesn't work yet! wat do you mena exactly with method get_p? is it the method of....?
in my solution scenario i did the following steps:
- Added a button in WEBUI (object BP_HEAD)
- I created BSP application and controller as you explained above
- in do_request method of this controller class i create PDF and format to xstring etc..
and i also set the following:
as you explane above.
- finally i set the code of
as you explane above in the click event of the webui button.
But solution doesn't work! can you say me please what i need to do to fix this?
do i forget somethink? where i can find method get_p? do i need to make a service via SICF?
I can open my PDF in a CRM popup but i want to open it in the web browser because the popup causes some problems when u use it in Citrix environment.
Please i hear from you.
Thanks in advance