Skip to Content
author's profile photo Former Member
Former Member

How to create a new record using ODataModel?

Hi,

I am new to UI5 and so ODataModel. I have tied one table to an ODataModel.

How would I send request to a server so that I will have a new entry created at server end?

I googled this and I tried following:

1. Called createEntry method on ODataModel as follows:

sap.ui.getCore().byId("maintainRolesTable").getModel().createEntry("DERMASSIGNMENTSet",{


"DeUser":"C5192081",

"SeqNo":"X",

"Childbp":"C5192081",

"ChildbpName":"",

"Id":"2",

"RelationType":"",

"Parentbp":"I0656568",

"ParentbpName":""

});


2. I called then submitChanges method on the model as follows:


sap.ui.getCore().byId("maintainRolesTable").getModel().submitChanges();


This is giving error as follows:


  1. POST https://lsftdc00.wdf.sap.corp:1443/sap/opu/odata/sap/ZSECENTRAL_SRV/DERMASSIGNMENTSet 403 (Forbidden) datajs.js:17
  2. 2014-06-05 16:53:32 The following problem occurred: HTTP request failed403,Forbidden,CSRF token validation failed -

When I try to use ajax call instead of these methods, I get error as follows:


var obj={

"Childbp": "C5192081",

"ChildbpName": "Supriya Kale",

"DeUser": "C5192081",

"Id": "8",

"Parentbp": "I0656568",

"ParentbpName": "",

"RelationType": "RESOURCE MANAGER",

"SeqNo": "1",

"metadata":{

"id":"https://lsftdc00.wdf.sap.corp:1443/sap/opu/odata/sap/ZSECENTRAL_SRV/DERMASSIGNMENTSet(DeUser='C5192081',SeqNo='x')",

"uri":"https://lsftdc00.wdf.sap.corp:1443/sap/opu/odata/sap/ZSECENTRAL_SRV/DERMASSIGNMENTSet(DeUser='C5192081',SeqNo='x')",

"type":"ZSECENTRAL_SRV.DERMASSIGNMENT"

},

};

$.ajax({

type: "PUT",

dataType: "json",

url: "https://lsftdc00.wdf.sap.corp:1443/sap/opu/odata/sap/ZSECENTRAL_SRV/DERMASSIGNMENTSet",

data: JSON.stringify(obj)

}).success(function( msg ) {

alert('HI read operation complete....................................');

}).error(function(msg){

alert("error occurred");

});



  1. I get following error:

  2. PUT https://lsftdc00.wdf.sap.corp:1443/sap/opu/odata/sap/ZSECENTRAL_SRV/DERMASSIGNMENTSet 403 (Forbidden)

Can anyone tell me if I am going wrong in calling methods? Help would be appreciated.


Thanks,

Supriya Kale




Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 05, 2014 at 12:01 PM

    Hi Supriya,

    try to call this function before submitChanges()

    sap.ui.getCore().byId("maintainRolesTable").getModel().refreshSecurityToken();


    Regards,

    Peter

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.