Quantcast
Channel: SCN : Discussion List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 6412

Problem while calling XSJS service from SAPUI5 ?

$
0
0

Screenshot 2014-01-24 14.34.02.png

 

I am getting OK status in Java Console. In response i can see result also which is correct.

But JQuery.ajax is hitting the error function call instead of success.

I tried hard but I am unable to figure out the reason.

Below I have attached my codes as well.  Let me know in case you need further information.

Please help.

 

{code}

// XSJSLIB

function getCustomer(empid){

  var name = '';

  var conn = $.db.getConnection();

 

 

  var query = 'SELECT \"NAME\" FROM \"project2\".\"MyPackage.data::table_header\" WHERE \"EMPID\" = ?';

  $.trace.debug(query);

  var pstmt = conn.prepareStatement(query);

  pstmt.setString(1,empid);

 

  var rs = pstmt.executeQuery();

  while(rs.next()){

  name = rs.getNString(1);

  }

 

  rs.close();

  pstmt.close();

 

  return name;

}

 

************

//XSJS

$.import("MyPackage.services","customer");

 

 

function discount(){

  var body = '';

  var mp = $.request.parameters.get('mp');

  var disc =    $.request.parameters.get('disc');

  var sp;

  var saletext = 'Sales  Price: $';

  var name = $.MyPackage.services.customer;

  var customer = name.getCustomer('1000000002');

 

  sp = ( ( mp * ( 100 - disc ) ) / 100 );

 

  body = saletext.concat(sp);

 

  $.response.setBody(body+ " for "+ customer);

  $.response.status = $.net.http.OK;

}

 

 

var sCmd = $.request.parameters.get('cmd');

switch(sCmd){

case "disc":

     discount();

     break;

default:

  $.response.status = $.net.http.INTERNAL_SERVER_ERROR;

    $.response.setBody('Invalid Command :'+ sCmd);

}

 

*************************

//VIEW.JS

createContent : function(oController) {
var discPanel = new sap.ui.commons.Panel().setText("Generate Sales Quote for Customer");

        discPanel.setAreaDesign(sap.ui.commons.enums.AreaDesign.Fill);

        discPanel.setBorderDesign(sap.ui.commons.enums.BorderDesign.Box);

       

        var layoutMP = new sap.ui.commons.layout.MatrixLayout({width: "auto"});

        discPanel.addContent(layoutMP);

        var oMPText = new sap.ui.commons.TextView("mptext",{text: "Marked Price: $", width: "100px"});

        var oMP = new sap.ui.commons.TextField("mp",{tooltip: "Marked Price", width: "100px", editable: true});

     

        var layoutDisc = new sap.ui.commons.layout.MatrixLayout({width: "auto"});

        discPanel.addContent(layoutDisc);

        var oDiscText = new sap.ui.commons.TextView("disctext",{text: "Discount: %", width: "100px"});

        var oDisc = new sap.ui.commons.TextField("disc",{tooltip: "Discount", width: "40px", editable: true});

     

        var layoutSP = new sap.ui.commons.layout.MatrixLayout({width: "auto"});

        discPanel.addContent(layoutSP);

        var oSPText = new sap.ui.commons.TextView("sptext",{width:"auto",text:"DEFAULT"});       

       

        oMP.attachEvent("liveChange", function(oEvent){

            oController.onLiveChangeMP(oEvent, oDisc);});

 

 

        oDisc.attachEvent("liveChange", function(oEvent){

       oController.onLiveChangeDisc(oEvent, oMP);});

       

        layoutMP.createRow(oMPText, oMP);

        layoutDisc.createRow(oDiscText, oDisc);

        layoutSP.createRow(oSPText);

       

       

       

        return discPanel;

}

 

 

});

*****************************

//CONTROLLER.JS

onLiveChangeMP: function(oEvent, oDisc){

  var aURL = '../../../services/sp.xsjs?cmd=disc'+'&mp='+escape(oEvent.getParameters().liveValue)+'&disc='+escape(oDisc.getValue());

  jQuery.ajax({

  url: aURL,

  method: 'GET',

  dataType: 'json',

  success: this.onGetSP,

  error:  this.onErrorCall

 

  });

  },

 

  onLiveChangeDisc: function(oEvent, oMP){

  var aURL = '../../../services/sp.xsjs?cmd=disc'+'&mp='+escape(oMP.getValue())+'&disc='+escape(oEvent.getParameters().liveValue);

  jQuery.ajax({

  url: aURL,

  method: 'GET',

  dataType: 'json',

  success: this.onGetSP,

  error:  this.onErrorCall

 

  });

  },

 

  onGetSP: function(myTxt){

  var oSPText = sap.ui.getCore().byId("sptext");

  oSPText.setText("onGetSP");

  } ,

 

  onErrorCall: function(myTxt){

  var oSPText = sap.ui.getCore().byId("sptext");

  oSPText.setText("OnErrorCall");

  }

***************************************************

// INDEX.HTML (SCRIPT SRC)

 

  <script src="/sap/ui5/1/resources/sap-ui-core.js"

  id="sap-ui-bootstrap"

  data-sap-ui-libs="sap.ui.commons,sap.ui.table"

  data-sap-ui-theme="sap_goldreflection">

  </script>

  <!-- add sap.ui.table,sap.ui.ux3 and/or other libraries to 'data-sap-ui-libs' if required -->

 

 

  <script>

 

</html>

{code}


Viewing all articles
Browse latest Browse all 6412

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>