Skip to end of metadata
Go to start of metadata


Link to Content's target Space :

 http://wiki.sdn.sap.com/wiki/display/CRM/CRM+Web+Client+UI+Framework

Applies to:

CRM 6.0/7.0

Summary

Uploading documents as attachments using cl_crm_documents class and displaying images in web ui screen.

Author(s):  

   
Company:     
Created on:   May'15 2010
Author(s) Bio
Arun Kumar is a CRM developer working with Accenture.

General description:

This wiki explains how to upload documents & images  using cl_crm_documents class and display images in web ui screen. The standard attachments tab lists the uploaded documents & images as individual links and the images are opened in a new window. This wiki also covers how to populate images in the standard web ui screen.

Implementation:

Create a component in transaction BSP_WD_CMPWB and add a view with view type 'Form View' or 'Empty View'. In this wiki its just an empty view without any context nodes.

The view  layout is enhanced with a fileupload tag to upload images and an image tag to display images.

The upload event triggers the server event EH_ONUPLOAD in controller class.

Event EH_ONUPLOAD:

The method gets triggered when user selects the file path and clicks Upload button.

The importing parameter htmlb_event_ex has reference to thtmlb:fileUpload tag. Assign htmlb_event_ex to reference variable lr_file of type ref to cl_htmlb_fileupload.

Extract filename and file extension from file path using function module 'CRM_KW_SPLIT_FILENAME'

Assign business object so that the file can be accessed from the specified business object location. Since the business object type is USER and instance identifier is sy-uname, the uploaded document can be accessed via transaction crm_kw.

The entire file content is stored as an xstring in lr_file->file_content. Since we use method create_with_table of cl_crm_documents class, the content is split into 1022 characters and inserted into an internal table.

Now, is the final step. Upload the document to the system using CREATE_WITH_TABLE method from class CL_CRM_DOCUMENTS.The method returns the logical and physical id's of the document location.

Now, the image is uploaded to the system. But in order to display the image we need to get the document location as a URL. It can be done by passing the logical and physical id's of the document to method GET_WITH_URL of class CL_CRM_DOCUMENTS.

The URL is assigned to public static variable gv_url.

In the layout the image location is passed through this variable <%= controller->gv_url. %>.

Screenshot:

Coding:

Layout Coding:

Method EH_ONUPLOAD:


Useful Information

Uploading documents and displaying images in web ui using CL_CRM_DOCUMENTS class.

 



Thanks & Regards,  Arun Kumar
  1. Guest

    Thank you very much for this posting, it's very helpful.

    I need to display a number of images (almost like very large buttons) that I can click on and have code executed accordingly. Can I ask what method I could use to achieve ths kind of functionality?. I can't use ordinary buttons as the images are square in shape, and I don't think you can add an image to standard buttons in this way.

    Jason

  2. Hi Jason,

    If you are adding buttons in prepare_toolbar method, then you can only use the images available in path 

    /SAP/BC/BSP/SAP/thtmlb_styles/sap_skins/default/images/.

    In case are creating the buttons directly in the layout page using thtmlb tags, then you can upload the images to the MIME repository of the same component & pass it to <thtmlb:button> tag parameter iconSrc,

    <thtmlb:button iconSrc="competitor.gif" tooltip="Competitor"  />

    Regards,

    Arun

  3. Guest

    Hello Arun,

    I have followed the above explained procedure to upload an image to the Web UI. But the image is not getting displayed. It is just showing the portion as coded in .htm page.

    Regards

    DNR Varma

  4. Guest

    Hello Arun,

    The way you provided the procedure was nice. I have followed the steps provided here and I am not getting the image in the view, but I am getting the success message as image was uploaded successfully. Is there any thing missed to display the image, please let me know.

    Thanks in advance.

    Regards,

    Darwin.

  5. Hi Darwin,

    Check whether the correct URL passed to the image tag in layout page,

    Regards,

    Arun

  6. Hi Darwin,

    Check whether the correct URL passed to the image tag in layout page,

    Regards,

    Arun

  7. Guest

    Hi Arun,

    Thanks for your response. The URL passed by me is

    <thtmlb:image src    = "<%= CONTROLLER->GV_URL %>"
                      width  = "175"
                      height = "175" />

    In debugging I found that, In event handler method eh_onupload, we are using a class

    CALL METHOD cl_crm_documents=>get_with_url
          EXPORTING
            loio     = ls_loio
            phio     = ls_phio
            url_type = '2'
          IMPORTING
            error    = ls_error
            url      = lv_url.

    from this class we should get

    lv_url value na, but it is not getting. could u can say me why it is not getting.

    Thanks and Regards,

    Darwin

  8. Hi Darwin,

     

    Plz declare the GV_URL as an global attribute in your View(IMPL class). Then only U can call that in .htm page.

     

    Regards,

    MOHAMED