cancel
Showing results for 
Search instead for 
Did you mean: 

Java script calling issue in SAP ABAP program - Error with 'return' statement

kalakonda4
Participant
0 Kudos

I am trying to call external BOT from GUI using its HTML/script, this works fine but when i try to send information like userid in the header parameter it doesn't work. When i debugged the program and tried the same html string in browser it throws error "Uncaught SyntaxError: Unexpected token return". Can you please check and let me know what am i doing wring in appending this string.

<<Created dummy BOT so i wont expose my actual token>>

DATA(html_str) =

     '<html>' &&

      ' <head>' &&

      '   <script>' &&

      '     window.webchatMethods = ' &&

      '      { getMemory: (conversationId) => { const memory = { userId: "E123456" }; ' &&

      '           return { memory, merge: true } } }' &&

      '   </script>' &&

      ' </head>' &&

      '  <body>' &&

      '   <script src= "https://cdn.cai.tools.sap/webchat/webchat.js" ' &&

      '     channelId="02b00be2-4fa1-435d-9650-e48e50831913" ' &&

      '     token="35bb6bbb74173f08e48ca51acc2b8740" ' &&

      '     id="cai-webchat" > ' &&

      '   </script>' &&

      '  </body>' &&

      '</html>' .



    cl_abap_browser=>show_html(

      EXPORTING

        html_string = html_str

*        modal       = modal

        position    = cl_abap_browser=>middle

        title       = title

        buttons     = cl_abap_browser=>navigate_html

        format      = cl_abap_browser=>portrait

        size        = cl_abap_browser=>small

*        data_table  = ext_data

      IMPORTING

         html_errors = error_list ).
Sandra_Rossi
Active Contributor
0 Kudos

SAP GUI used to use an internal Microsoft Web Browser control to render HTML and interpret javascript, so I guess it's too old for your code.

Sandra_Rossi
Active Contributor
0 Kudos

Your ABAP code is altered after <body>. To avoid SAP Community platform alter your code, select it and press the "CODE" button to make it correctly colorized/indented, so that it's easier for us to analyze it. Thank you.

Sandra_Rossi
Active Contributor
0 Kudos

As I said, it's a very old internal Microsoft Web Browser which is no more supported.

Either you use the latest SAP GUI and you install WebView2 so that to work with Chromium, or you adapt your javascript code, for instance like:

...
      '     window.webchatMethods = ' &&
      '      { getMemory: getMemory() };' &&
      'function getMemory(conversationId) { ' &&
      '           return { userId: "E123456" , merge: true } }' &&
...
kalakonda4
Participant
0 Kudos

Thanks Sandra, looks like you are spot on. We have the latest GUI 7.6 but it still has IE, SAP recently released 7.7 integrating the Microsoft WebView2 control which we are not on.

I tried the same script by saving as HTML file, it gets desired results in all browsers but not in IE which tells why its not working with GUI 7.6 if it has IE integrated.

For now we don't have a roadmap for SAP GUI 7.7, i tried to adapt the script as per your suggestion but as the code is from SAP CAI webchat channel, it throws error saying function doesn't exist.


Any other suggestion here please, i am relatively new to this scripting, sorry 🙂

DATA(html_str) =
     '<html>' &&
      ' <head>' &&
      '   <script>' &&
      '     window.webchatMethods = ' &&
      '      { getMemory: getMemory() };' &&
      'function getMemory(conversationId) { ' &&
      '           return { userId: "E123456" , merge: true } }' &&
      '   </script>' &&
      ' </head>' &&
      '  <body>' &&
      '   <script src= "https://cdn.cai.tools.sap/webchat/webchat.js" ' &&
      '     channelId="02b00be2-4fa1-435d-9650-e48e50831913" ' &&
      '     token="35bb6bbb74173f08e48ca51acc2b8740" ' &&
      '     id="cai-webchat" > ' &&
      '   </script>' &&
      '  </body>' &&
      '</html>' .

View Entire Topic
kalakonda4
Participant
0 Kudos

Was able to resolve this issue after adapting the java script code to IE standards. Thanks for all the insights.