cancel
Showing results for 
Search instead for 
Did you mean: 

How to insert data from SAP ui5 screen to database using XSJS service?

former_member594414
Participant
0 Kudos

Hi All,

This may be a repetitive question, but I find it difficult to fetch data from UI screen using AJAX POST request. Below is the code snippet of the ajax request that is a part of the index.html file

$.ajax({
url : 'https://ajrbt0xgat8bnan8-new-newjs.sg11scbh1ddd0.hec.xxxx:30033/test.xsjs',
type : 'POST',
contentType : 'application/json',
data : JSON.stringify(oEntry),
dataType : 'json',
success : function(data) {         
alert(data);
},
error : function(error) {     
alert("Error Inserting Data")
},
});

And below is the xsjs file that consumes the data

var data1 = $.request.body.asString();  
var d = JSON.parse(data1);
$.response.contentType = 'text/html';
$.response.setBody(d[0].EMAIL);
$.response.headers.set("Access-Control-Allow-Origin", "*");
$.response.status = 200;  

Problem here is the xsjs service is not invoked as I get the alert "Error Inserting Data"

Please help and guide as I'm new to SAP HANA on whole.

Accepted Solutions (0)

Answers (2)

Answers (2)

SergioG_TX
Active Contributor

what does the json payload look? are you able to at least get to the xsjs service?

the code to read the payload in your xsjs service looks ok. have you tried debugging on your xsjs side? if you have the debugging role, you can debug from the web workbench by setting a break point and seeing what is received on your service...

alternatively, wrap your xsjs code in a try catch and see what the error is after invoking the service. also does your object contains all the properties that your back end is expecting (contract) that may also be something to look at and make sure all the expected properties are mapped

gregorw
Active Contributor
0 Kudos

You might check out SITreg and it's corresponding SAPUI5 applications for some examples.