Skip to Content
0

I can't make a POST Request to an oData Service ! ( uncaught exception: [object Object] ).

Nov 27, 2017 at 04:05 PM

39

avatar image
Former Member

I'm trying to post data to an oData service using SAPUI5 Application.

And I get the following error : uncaught exception: [object Object].

How can I change the Access-Control-Allow-Methods ?

Anyone have an idea on how to solve this problem ?

THANK YOU

10 |10000 characters needed characters left characters exceeded

Please share your code snippets and manifest.json file. And also tell me are executing this application in Fiori Launchpad?

0
Former Member

Please check the screenshots in the comments. I'm working on Eclipse. Thank you Irfan.

0
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Arjun Biswas Nov 28, 2017 at 07:38 AM
0

Hi Khalil RAHMANI,

From what I understand, you must not have implemented the create entity method in your back end or you have provided the credentials wrong . Share screenshots of your error and code.

Show 4 Share
10 |10000 characters needed characters left characters exceeded
Former Member

I keep getting this error when I'm submitting the form. Thank you.

error1.png (55.0 kB)
error2.png (31.4 kB)
0
Former Member

This the main.controller.js file

1.png (22.5 kB)
2.png (22.7 kB)
0
Former Member

The rest of the file :

3.png (31.1 kB)
4.png (9.6 kB)
0

Hi Khalil RAHMANI,

Thanks for sharing the screenshots.

I am going to suggest you another method for POST operations, using the create() method in odata. Please go through the foll. link for more information about the method :

https://sapui5.hana.ondemand.com/#/api/sap.ui.model.odata.ODataModel --- Seach for create under methods

Please refer to the foll. example for better understanding of the POST operation :

Create your model :

var modelo = new
sap.ui.model.odata.ODataModel("proxy/http/183.82.98.148:8048/sap/opu/odata/SAP/****_SRV",false,"Your_username","Your_Password");

Now create your form :

var oSimpleForm = new
sap.ui.layout.form.SimpleForm("sf1", 


                                        {


                                                content:[


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


                                                                new
sap.ui.commons.TextField({width : "15em"}),


                                                                


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


                                                                new
sap.ui.commons.TextField({width : "15em"}),


                                                                


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


                                                                new
sap.ui.commons.TextField({width : "15em"}),


                                                                


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


                                                                new
sap.ui.commons.TextField({width : "15em"}),


                                                                


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


                                                                new
sap.ui.commons.TextField({width : "15em"}),


                                                                


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


                                                                new
sap.ui.commons.TextField({width : "15em"}),


                                                                


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


                                                                new
sap.ui.commons.TextField({width : "15em"}),


                                                                


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


                                                                new
sap.ui.commons.TextField({width : "15em"})


                                                                


                                                                ]});

Now to POST all the entered data in the form,

function insertData(){


                                var form =
oSimpleForm.getContent();


                                


                                var entry = {};


                                entry.Empid
= form[1].getValue();


                                entry.Firstname
= form[3].getValue();


                                entry.Lastname
= form[5].getValue();


                                entry.Age
= form[7].getValue();


                                entry.Mobileno
= form[9].getValue();


                                entry.Salary
= form[11].getValue();


                                entry.Eposition
= form[13].getValue();


                                entry.Email
= form[15].getValue();


                         

                        sap.ui.getCore().setModel(modelo);


                        sap.ui.getCore().getModel().create("/employeeinfoSet",entry,null,function(oResponse){


                                                                                                        sap.ui.commons.MessageBox.alert("Create
Successfull");


                        },function(){


                                sap.ui.commons.MessageBox.alert("Create
Failed");


                        });


                        


                        }

Your final output looks something like this :

So, by using the model_object.create() method, you can perform POST operation in ODATA.

Hope this helps,

Regards.

create.png (36.0 kB)
0