Skip to Content
avatar image
Former Member

Unable to create a record in sap ui5 table(Client browser)?

I have tried create opertion in sapui5 using odata service.I am able to consume the data using odata service.I have gone through some reference to fix my errors but unable to fixt it !!!

The code which i tried

CONTROLLER.js

onInit: function()

{

var oModel= new sap.ui.model.odata.ODataModel("proxy/http/services.odata.org/V2/(S(o4ssuvwfqdr2ofkog3ztc2lr))/OData/OData.svc");

oModel.oHeader={ "DataServiceVersion": "2.0", "MaxDataServiceVersion": "2.0" }; sap.ui.getCore().setModel(oModel,"products");

},

mode: 0,

resetForm: function() {

$("#name").val('');

$('#description').val('');

$('#price').val('');

$('#rating').val('');

$('#id').val('');

},

create: function() {

this.mode = 'create'; this.resetForm(); $("#formId").slideDown(300, function()

{

var id = sap.ui.getCore().byId('tableId')._getRowCount();

$("#id").val(id);

});

},

edit: function(){ },

remove: function(){ },

save: function()

{

var requestObj = { requestUri: '', method: '', headers: {

"X-Requested-With": "XMLHttpRequest",

"Content-Type": "application/json;odata=minimalmetadata", "DataServiceVersion": "2.0", "MaxDataServiceVersion": "2.0", "Accept": "application/json;odata=minimalmetadata" }

};

var newData={ "odata.type": "ODataDemo.Product",

"ID": $("#id").val(),

"Name": $("#name").val(),

"Description": $("#description").val(),

"Price": $("#price").val(),

"Rating": $("#rating").val(),

"ReleaseDate": $("date").val(),

"Price": $("#price").val(),

"Rating":$("#rating").val()

}

if(this.mode == 'create')

{ var url= "proxy/http/services.odata.org/V2/(S(o4ssuvwfqdr2ofkog3ztc2lr))/OData/OData.svc";

var method= "POST";

requestObj.requestUri = url;

requestObj.method = method;

requestObj.data = newData;

}

OData.request(requestObj, function() {

sap.ui.getCore().getModel('products').refresh();

$("#formId").slideUp();

});

}

});

view.js

createContent : function(oController) {

var oMatrix = sap.ui.commons.layout.MatrixLayout({ layoutFixed : true, width : "300px", column : 3 });

oMatrix.createRow( new sap.ui.commons.Button({ text:"Create", width : "100px", press:function() { oController.create();

}

}),

new sap.ui.commons.Button({ text:"Edit", width : "100px", press:function() { oController.edit();

}

}),

new sap.ui.commons.Button({ text:"Delete", width : "100px", press:function() { oController.remove(); }

}) );

var oLayout = new sap.ui.layout.form.SimpleForm("formId",{ title:"Product Maintainence", content:[ new sap.ui.commons.Label({text:"ID"}),

new sap.ui.commons.TextField("id",{width:'200px',editable:false}),

new sap.ui.commons.Label({text:"Name"}),

new sap.ui.commons.TextField("name",{width:'200px'}),

new sap.ui.commons.Label({text:"Description"}),

new sap.ui.commons.TextField("description",{width:'200px'}),

new sap.ui.commons.Label({text:"Price"}),

new sap.ui.commons.TextField("price",{width:'200px'}),

new sap.ui.commons.Label({text:"Rating"}),

new sap.ui.commons.TextField("rating",{width:'200px'}),

new sap.ui.commons.Label({text:"ReleaseDate"}),

new sap.ui.commons.TextField("date",{width:'200px',value:"2016-12-28T22:22:22"}),

new sap.ui.commons.Label({text:""}),

new sap.ui.commons.Button({ text:"Save", width:'100px', press: function(){ oController.save()

} })

] });

//table var oTable = new sap.ui.table.Table("tableId",{ visibleRowCount :5, editable :false }); oTable.addColumn(new sap.ui.table.Column({ label: new sap.ui.commons.Label({text:"ID"}), visible : true,

template : new sap.ui.commons.TextView({text: "{products>ID}"}) })); oTable.addColumn(new sap.ui.table.Column({ label : new sap.ui.commons.Label({text: "Name"}), visible : true, template : new sap.ui.commons.TextView({text: "{products>Name}"})

}))

oTable.addColumn(new sap.ui.table.Column({ label : new sap.ui.commons.Label({text: "Description"}),

visible : true, template : new sap.ui.commons.TextView({text: "{products>Description}"})

}));

oTable.bindRows("products>/Products");

// var ele=[oMatrix,oTable,oLayout]; return ele; }

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

0 Answers