cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

CRM 2007: download HTML file from Web UI

0 Kudos
405

Hi all,

I have to download an html smartform from Web UI. I've created a new button in the view and on setted its attribute on_client_click with the url created with create_service_script method of cl_crm_web_utility:


lv_url = cl_crm_web_utility=>create_service_script(
      iv_handler_class_name   = 'YWCRM_CL_INVENT_DOWNL_HANDLER'
*      iv_controller_id        = controller_name
      iv_absolute             = 'X'
      iv_query                = lv_query
      iv_in_same_session      = 'X'
      iv_no_cookie            = 'X'
*      iv_prevent_url_mangling = SPACE
*      iv_js_callback_function =
    ).

...
ls_button-on_client_click = lv_url.
...

I'm using crm generic callback, so I've created a new handler class (YWCRM_CL_INVENT_DOWNL_HANDLER). In its IF_CRM_WEB_CALLBACK~HANDLE_REQUEST method I've written code to get smartform data and put in response:



data: lv_content_bin type xstring.

...

CALL FUNCTION 'YWCRM_INVENTARIZATION_HTML'
  EXPORTING
    iv_object_guid           = lv_guid
    iv_smartforms_name       = lv_smartform_name
 IMPORTING
   EV_XSTRING               = lv_content_bin
*     ES_XML_OUTPUT            =
*     ET_HTML_RAW              =
  tables
    et_binary_output         = lt_out
 EXCEPTIONS
   INVALID_FORMS            = 1
   FILE_NOT_SAVED           = 2
   OTHERS                   = 3
          .

ir_server->response->set_header_field( name  = 'Content-Type'"#EC NOTEXT
                                       value = 'text/html' ).

ir_server->response->set_data( data = lv_content_bin ).

Even if lv_content_bin variable is not initial I can't see any "Save file as" message frowm the browser, and I can't download file.

Actually nothing seems to happen, even all the code is executed without any exception.

Any hints?

Thank you so much in advance!

Cheers

Luca

Accepted Solutions (0)

Answers (1)

Answers (1)

0 Kudos

Issue solved!!!!

That's what I've done, maybe someone will find it useful.

Instead of create_service_script method above, I've used create_service_url method:


  lv_url = cl_crm_web_utility=>create_service_url(
      iv_handler_class_name   = 'YWCRM_CL_INVENT_DOWNL_HANDLER'
*      iv_controller_id        = controller_name
      iv_absolute             = 'X'
      iv_query                = lv_query
      iv_in_same_session      = 'X'
      iv_no_cookie            = 'X'
*      iv_prevent_url_mangling = SPACE
*      iv_js_callback_function =
    ).

lv_url variable holds only the url that will launch the handler class.

In order to launch the url the on_client_client attribute of the button contain a javascript window.location attribute set:


CONCATENATE 'javascript:window.location=''' lv_url ''';' into lv_url.

Clicking on the button will launch the correct url and the browser takes care of the rest, asking if nad where you want download the file!!

Former Member
0 Kudos

Hi Luca,

I have requirement similar to your but may be simple.

I just wanted to call a smart form a button in WEB UI Billing Tab.

Can you provide me any inputs and How to proceed.

Thanks,

Sree.

0 Kudos

Hello Sree,

you can just try to implement code above creating a service url and the calling it from your custom event of your button.

Following the code you could use in you event:


lv_url = cl_crm_web_utility=>create_service_url(
      iv_handler_class_name   = '<your event handler>'
*      iv_controller_id        = controller_name
      iv_absolute             = 'X'
      iv_query                = lv_query
      iv_in_same_session      = 'X'
      iv_no_cookie            = 'X'
*      iv_prevent_url_mangling = SPACE
*      iv_js_callback_function =
    ).


* this is the javascript to open a popup 
CONCATENATE 'javascript:window.location=''' lv_url ''';' into lv_url.

* link the url to button click event
ls_button-on_client_click = lv_url.

Event handler class must implement IF_CRM_WEB_CALLBACK interface. In HANDLE_REQUEST method you should call the smartform and then set the appropriate mime data.


ir_server->response->set_header_field( name  = 'Content-Type' "#EC NOTEXT
                                                                  value = '<your content type>' ). "content type is html, pdf, etc

ir_server->response->set_data( data = lv_content_bin ). "lv_content_bin is the smartform in a binary form.

Hope this helps!

Luca

Former Member
0 Kudos

I am facing a similar issue and would like to ask for a sample implementation of this handler class.

What interface do you implement to handle the request properly?

Currently I implement IF_CRM_WEB_CALLBACK but it redirects the CRM to a white page which is not what I want. I just want to return an XML file.

Thanks!