Skip to Content

Some time we need company image to be display on survey.

So below given are few steps to add image in survey.

Steps to add  image into survey:-


  1. Go to transaction CRM_SURVEY_SUITE.
  2. Select the required application (Marketing in this case) as :-

3) After selection of required survey from application, click on Maintain Survey Attributes button.

4) After click on this button following window will appear.

5) Now we have to copy the standard function module CRM_MKTCA_SURVEY_MKT_PBO to our Z FM so that we can make required changes into it.

Add following code into this Z (PBO) FM.


CONSTANTS: lc_link_to_picture TYPE string
VALUE IMAGE LINK  ‘.

   DATA: lt_javascript   TYPE survy_t_javascript,
ls_javascript   TYPE survy_s_javascript,
lt_svy_on_event TYPE survy_t_on_event,
ls_svy_on_event TYPE survy_s_on_event.

* <Create and insert JavaScript>
   ls_javascript-name     = ‘insertImage’. “#EC NOTEXT
   ls_javascript-language = ‘JavaScript1.3’. “#EC NOTEXT
   ls_javascript-script   = ‘function insertImage() {‘. “#EC NOTEXT
   CONCATENATE ls_javascript-script
  ‘var nodeDiv = document.createElement(”div”);’
  ‘nodeDiv.setAttribute(“align”, “center”);’
  ‘var nodeImg = document.createElement(”img”);’
INTO ls_javascript-script. “#EC NOTEXT

   CONCATENATE ls_javascript-script
  ‘nodeImg.setAttribute(“src”, “‘ lc_link_to_picture ‘”);’
  ‘nodeImg.setAttribute(“alt”, “”);’
  ‘nodeDiv.appendChild(nodeImg);’
INTO ls_javascript-script. “#EC NOTEXT

   CONCATENATE ls_javascript-script
  ‘document.getElementsByTagName(”body”)[0].insertBefore’
  ‘(nodeDiv, document.getElementsByTagName(”body”)[0].firstChild);}’
INTO ls_javascript-script. “#EC NOTEXT

   APPEND ls_javascript TO lt_javascript.

   CALL METHOD ir_survey_values->javascript_add
     EXPORTING
       it_script = lt_javascript.

  ls_svy_on_event-question_id   = ‘html’.                       “#EC NOTEXT
  ls_svy_on_event-answer_id     = ‘body’.                       “#EC NOTEXT
  ls_svy_on_event-name          = ‘onLoad’.                     “#EC NOTEXT

  CONCATENATE ls_javascript-name ‘()’ INTO ls_svy_on_event-call_function.”#EC NOTEXT

  APPEND ls_svy_on_event TO lt_svy_on_event.

  CALL METHOD ir_survey_values->on_event_add
    EXPORTING
      it_on_event = lt_svy_on_event.


6) Assign your Z FM to Callback PBO as:-

Function Module CRM_SVY_EXAMPLE_DYNAMIC_PBO has code example for this.

And also contains some other code examples.

Hope it will help…

Regards,

Harish Kumar

To report this post you need to login first.

22 Comments

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

  1. sap crm

    Thanks Harish for Quick reply..

    I write the below code in my ZPBO Method exactly what in that FM…..

    But it is not coming…. Should we do anything extra in that ?

       Set the link to the picture
      CONSTANTS: lc_link_to_picture TYPE string
                                    VALUE http://www.sap.com/global/images/sap_logo.gif‘.

      DATA: lt_javascript   TYPE survy_t_javascript,
            ls_javascript   TYPE survy_s_javascript,
            lt_svy_on_event TYPE survy_t_on_event,
            ls_svy_on_event TYPE survy_s_on_event.

    * <Create and insert JavaScript>
      ls_javascriptname     = ‘insertImage’.                   “#EC NOTEXT
      ls_javascriptlanguage = ‘JavaScript1.3’.                 “#EC NOTEXT
      ls_javascriptscript   = ‘function insertImage() {‘.      “#EC NOTEXT
      CONCATENATE ls_javascriptscript
                  ‘var nodeDiv = document.createElement(‘‘div’‘);’
                  ‘nodeDiv.setAttribute(“align”, “center”);’
                  ‘var nodeImg = document.createElement(‘‘img’‘);’
                  INTO ls_javascriptscript.                    “#EC NOTEXT

      CONCATENATE ls_javascriptscript
                  ‘nodeImg.setAttribute(“src”, “‘ lc_link_to_picture ‘”);’
                  ‘nodeImg.setAttribute(“alt”, “”);’
                  ‘nodeDiv.appendChild(nodeImg);’
                  INTO ls_javascriptscript.                    “#EC NOTEXT

      CONCATENATE ls_javascriptscript
                  ‘document.getElementsByTagName(‘‘body’‘)[0].insertBefore’
                  ‘(nodeDiv, document.getElementsByTagName(‘‘body’‘)[0].firstChild);}’
                  INTO ls_javascriptscript.                    “#EC NOTEXT

      APPEND ls_javascript TO lt_javascript.

      CALL METHOD ir_survey_values->javascript_add
        EXPORTING
          it_script = lt_javascript.
    * </Create and insert JavaScript>

    * <Assign script to event onLoad in the BODY-tag>
      ls_svy_on_eventquestion_id   = ‘html’.                       “#EC NOTEXT
      ls_svy_on_eventanswer_id     = ‘body’.                       “#EC NOTEXT
      ls_svy_on_eventname          = ‘onLoad’.                     “#EC NOTEXT
      CONCATENATE ls_javascriptname ‘()’ INTO ls_svy_on_eventcall_function.“#EC NOTEXT

      APPEND ls_svy_on_event TO lt_svy_on_event.

      CALL METHOD ir_survey_values->on_event_add
        EXPORTING
          it_on_event = lt_svy_on_event.
    * </Assign script to event onLoad in the BODY-tag>

    (0) 
  2. sap crm

    Thanx once again Harish, I will check and let u know.

    Another issue also I am facing. Do u face any issuelike this before.

    I am getting an error that

    Survey Was not Found or Is not Within the Validity Period.

    Why I am getting this error. =>

    I have added one save button whose Function Code is SAVE. Rather tha SUBMIT AND RESET as of standard

    When I test in GUI it is working fine.

    But when I create the URL and test it at that time

    whenever I am pressing save or pressing enter in that Survey URL, I am getting this error.

    Should I have to write any code for Function Code “SAVE”.

    Where to write? How to solve this error?

    (0) 
    1. sap crm

      Hi Harish,

      Did you encountere the above issue ?

      I also posted this in separate discussion but didn’t get any reply thats why posting here…

      (0) 
  3. SaiSrinivas Ivaturi

    Hi Harish,

    Thanks a lot for your blog. This was really helpful.

    Also, I am trying to modify the existing survey template so that it includes an option to browse and upload an image instead of enhancing the FM for each survey seperately. This would then be a more generalized option which will allow to upload different image in different surveys as per the requirement.

    Any help would be appreciated.

    Thanks

    Srini

    (0) 
  4. Joyca Vervinckt

    Dear,

    Adding the image works, however it only seems to work in Internet Exporer…

    In Chrome, Firefox, …, the image is not displayed.

    Is there anything that can be done about that?

    Kind regards,

    Joyca

    Update: We found the cause, it was because we were trying out things in the code around the “allign – center” part. When removing the “center”, IE still accepts this, but other browsers not.

    (0) 

Leave a Reply