Hello,
does anyone have a working example or a simple explanation of a create operation for OData services in HTML / JavaScript / AngularJS?
I want to create new entities on my existing database. Is this also doable via URL (I dont think so)?
Thanks in advance,
yours truly,
Leon
Hi,
you asked for a basic example, I hope this will help.
(It's very basic, just to give you an idea.)
//first, we create a button to press and call the update
var myButtonInsert = new sap.ui.commons.Button("btninsert");
myButtonInsert.setText("Insert Comment");
myButtonInsert.attachPress(function() {
onInsert();
});
// define the Table columns
var oControl1 = new sap.ui.commons.TextView({text:"{COMMENT_ID}"}); // short binding notation
oTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Comment ID"}),
template: oControl1,
sortProperty: "commentID",
filterProperty: "commentID",
width: "100px"}));
.... More columns ....
var oEntry = {};
function onInsert() {
var aUrl = 'https://___.hana.ondemand.com/___/demo/belliotj/XsProjectJb/Services/ModifyComment.xsodata/comment';
oEntry.COMMENT_ID = commentID.getValue();
oEntry.DATE = date.getValue();
oEntry.USER_ID = userID.getValue();
oEntry.COMMENT_TEXT = commentText.getValue();
oEntry.POST_ID = postID.getValue();
// https://___.hana.ondemand.com/___/demo/belliotj/XsProjectJb/Services/ModifyComment.xsodata/comment
jQuery.ajax({
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
url: aUrl,
type: 'POST',
dataType: 'json',
data: JSON.stringify(oEntry),
success: function() {
alert("Record Inserted");
onRefresh();
},
error: function() {
alert("Insert Failed");
}
});
}
The result is a form that will add a record to a HANA database, so perform a POST operation.
Jonathan
Have a look at SHINE (SAP HANA Interactive Education). There are examples there. The only difference is they use SAPUI5 and not Angular JS on the client side.
http://help.sap.com/hana/SAP_HANA_Interactive_Education_SHINE_en.pdf
Add a comment