Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

Use case:

Invoke xsjs application from html.

Most people may know about debugging an xsjs application using the hdbstudio.

Supposing, for some reason, the debug configuration is not able to connect to the correct session, there is an alternate way to debug the application.

HTML snippet - MyHTML.html:

<HTML>

<SCRIPT>

....

          function onBody() {

          var aUrl = '../services/MyService.xsjs';

          jQuery.ajax({

          url: aUrl,

          method: 'GET',

          dataType: 'json',

          success: this.onCompleteBody,

          error: this.onBodyError

          });

          }

          function onBodyError(myTxt){

              alert(myTxt.statusText);

          }

          function onCompleteBody(myTxt){

              oModel.setData({ bData : myTxt });

         }

....

</SCRIPT>

  

<body  onLoad=onBody()>

....

</body>

</html>

================= End of MyHTML.html ================

MyService.xsjs:

  

var errtxt='';     // Empty string

try

{

errtxt += '1:';

SQL statement 1

...

errtxt += '2:';

SQL statement 2;

  

....

errtxt += 'n:';

SQL statement n;

$.response.contentType = 'application/json';
  $.response.setBody(correct_output);
$.response.status = $.net.http.OK; 

}

  catch (err)

{

$.response.contentType = 'text/plain';
errtxt += ':Error : ' + err;
$.response.setBody(errtxt );
$.response.status = $.net.http.INTERNAL_SERVER_ERROR; 

}

---------  END of MyService.xsjs ---------------

  

Using chrome or firefox run the MyHTML.html in developer mode and debug it.

Set break point at

          function onBodyError(myTxt){

           >   alert(myTxt.statusText);   // break point at alert

          }

If there is any error you can view the object myTxt contents and the myTxt.responseText will show the errtxt set in MyService.xsjs.

This will show on which SQL statement, the xsjs failed along with error code.

Hope this helps your debugging efforts.

1 Comment
Labels in this area