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>' .

Accepted Solutions (0)

Answers (3)

Answers (3)

kalakonda4
Participant
0 Kudos

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

maheshpalavalli
Active Contributor
0 Kudos

That error is coming because of the missing ";" for the getmemory function. But I believe the HTML itself is incorrect, I assume you pasted the code partially for reference.

'<html>' &&
' <head>' &&
' <script>' &&
' window.webchatMethods = ' &&
' { getMemory: (conversationId) => { const memory = { userId: "123456" }; ' &&
' return { memory, merge: true } } }' &&
' </script>' &&
' </head>' &&
' <body>' &&
' channelId="3132871f-xxxx-xxxx-xxxx-xxxxxxxxxx" ' &&
' token="32556652365XXXXXXXXXX" ' &&
' id="cai-webchat" > ' &&
' </script>' &&
' </body>' &&
'</html>' .
kalakonda4
Participant
0 Kudos

Updated my question to show the exact code along with values. It still doesnt read the value and when i copy the HTML string table value and test it gives same error in browser.

jyguyomarch
Advisor
Advisor
0 Kudos

Hi,

Try using single quotes (or not quotes if it is just a number) for your userId. It did the trick for me: https://jsbin.com/macuvotoji/edit?html,output

You are also missing part of the WebChat script, but I assume it is a copy paste error.

BR - Jean-Yves

kalakonda4
Participant
0 Kudos

Thank you for quick reply. Script works fine when i use outside of ABAP program but the issue is when i integrated inside ABAP program and align it as string text. Below program layout.

Please let me know if i am missing anything at 'return' statement.