cancel
Showing results for 
Search instead for 
Did you mean: 

How to call xsjs service for to display data in ui5 screen in SAP HANA XSA?

former_member594414
Participant
0 Kudos

Hi All,

I'm trying to create a screen that contains basic details of employee. The data will be fetched from a database via a xsjs service. Below is the code of the service

var select_all_personals_query =  
                    "select * from \"newcds.employee\"";  
function close(closables) {  
          var closable;  
          var i;  
          for (i = 0; i < closables.length; i++) {  
                    closable = closables[i];  
                    if(closable) {  
                              closable.close();  
                    }  
          }  
}  
function getDataPersonals(){  
          var x1 = {
              UserSet: str
              };
          var dataPersonalsList = [];  
          var connection = $.db.getConnection();  
          var statement = null;  
          var resultSet = null;  
          try{  
                    statement = connection.prepareStatement(select_all_personals_query);  
                    resultSet = statement.executeQuery();  
                    var dataPersonal;  
             
                    while (resultSet.next()) {  
                              dataPersonal = {};  
                              dataPersonal.EMAIL = resultSet.getString(1);  
                              dataPersonal.FIRSTNAME = resultSet.getString(2);  
                              dataPersonal.LASTNAME = resultSet.getString(3);
                              dataPersonal.AGE = resultSet.getString(4);                              
                              dataPersonal.ADDRESS = resultSet.getString(5); 
                              dataPersonalsList.push(dataPersonal);  
                    }  
          } finally {  
                    close([resultSet, statement, connection]);  
          }  
//JSON.stringify(obj);        // '"bar"'
//JSON.stringify({ x: obj }); // '{"x":"bar"}'          
                var str = JSON.stringify({UserSet: dataPersonalsList});   
         return str;  
}  
function doGet() {  
          try{  
                    $.response.contentType = "application/json";  
                    $.response.setBody(getDataPersonals());             
          }  
          catch(err){  
                    $.response.contentType = "text/plain";  
                    $.response.setBody("Error while executing query: [" + err.message + "]");  
                    $.response.returnCode = 200;  
          }  
}  
doGet();  

The service works fine and below is the JSON Output

{"UserSet":[{"EMAIL":"dirk.brian@example.com","FIRSTNAME":"Dirk","LASTNAME":"Brian","AGE":"49","ADDRESS":"Exeter, England"}]}

Now I have created a ui5 screen using SAP ui5 HTML module in XSA WEB IDE. Below is the index.html of the screen

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>


<!-- Load UI5, select gold reflection theme and the "commons" and "table" control libraries -->
  <script id='sap-ui-bootstrap' type='text/javascript'
    src='https://sapui5.hana.ondemand.com/resources/sap-ui-core.js'
    data-sap-ui-theme='sap_bluecrystal'
    data-sap-ui-libs='sap.ui.commons,sap.ui.table'></script>
        <!-- only load the mobile lib "sap.m" and the "sap_bluecrystal" theme -->


        <script>
            jQuery(function() {
  
  // instantiate the table
  var oTable = new sap.ui.table.Table({
    selectionMode : sap.ui.table.SelectionMode.Single,
    selectionBehavior: sap.ui.table.SelectionBehavior.Row
  });


  // define the Table columns and the binding values
  oTable.addColumn(new sap.ui.table.Column({
    label: new sap.ui.commons.Label({text: "EMAIL"}), 
    template: new sap.ui.commons.TextView({text:"{EMAIL}"})
  }));


  oTable.addColumn(new sap.ui.table.Column({
    label: new sap.ui.commons.Label({text: "FIRST NAME"}), 
    template: new sap.ui.commons.TextField({value: "{name}"})
  }));


  oTable.addColumn(new sap.ui.table.Column({
    label: new sap.ui.commons.Label({text: "LAST NAME"}), 
    template: new sap.ui.commons.CheckBox({checked: '{LName}'})
  }));
  
  oTable.addColumn(new sap.ui.table.Column({
    label: new sap.ui.commons.Label({text: "AGE"}), 
    template: new sap.ui.commons.CheckBox({checked: '{age}'})
  }));
  
  oTable.addColumn(new sap.ui.table.Column({
    label: new sap.ui.commons.Label({text: "ADDRESS"}), 
    template: new sap.ui.commons.CheckBox({checked: '{address}'})
  }));
  
  // create some local data
 // var naughtyList = [
  //  {lastName: "Dente", name: "Al", stillNaughty: true},
  //  {lastName: "Friese", name: "Andy", stillNaughty: true},
  //  {lastName: "Mann", name: "Anita", stillNaughty: false}
 // ];


  var oModel = new sap.ui.model.json.JSONModel("https://ajrbt0xgat8bnan8-new-newjs.sg11scbh1ddd0.hec.sta.com:30033/jsondata.xsjs", false);
 // oModel.setData(naughtyList);
  oTable.setModel(oModel);
  oTable.bindRows("/UserSet");
  oTable.placeAt("content");
});
        </script>


    </head>
    <body class="sapUiBody" role="application">
        <div id="content"></div>
    </body>
</html>

The problem is I get the screen with "No Data". The problem is loading the json output from the link. The JSON output as given above is not getting loaded.

I tried with a JSON input "naughty list" which is working fine, but loading json input from url link is the issue. I'm not sure how to solve it. Kindly help.

Accepted Solutions (0)

Answers (1)

Answers (1)

junwu
Active Contributor
0 Kudos

any error at console?

is the ajax call going out?

former_member594414
Participant
0 Kudos

This is something I get

#ERROR#/Handler#########1pdSOd-GK07w5A31Fg8V09x6a_tUfhDq######jo7y6tde#PLAIN##GET request to //favicon.ico completed with status 404 - ENOENT: no such file or directory, stat '/hana/shared/H1D/xs/app_working/sg11scbh1ddd0/executionroot/7154cb4a-faf6-4a3a-bacc-296f46924433/app/resources/favicon.ico'#