如何通过使用公共OData(读写)服务添加新记录?

2020-09-13 01:24发布

点击此处---> 群内免费提供SAP练习系统(在群公告中)加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)尊敬的SAP专家 我已经...

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


尊敬的SAP专家

我已经使用SAP WEB IDE Full-Stack工具创建了一个简单的UI5 Web应用程序。 我从 https://services.odata.org/V2/(S(zgiajht3rj0txzdxqds0itlv))/OData/OData.svc/Products ,数据将正确显示。

现在,我希望我也可以添加新记录。 我已经创建了表单,还有一个提交数据的按钮。 我还创建了如下控制器:

 handleSave:function(){
 var newData = {
 " odata.type":" ODataDemo.Product",
 " ID":this.getView()。byId(" InputID")。getValue(),
 "名称":this.getView()。byId(" InputName")。getValue(),
 "说明":this.getView()。byId(" InputDescription")。getValue(),
 " ReleaseDate":this.getView()。byId(" InputReleaseDate")。getValue(),
 " DiscontinuedDate":this.getView()。byId(" InputDiscontinuedDate")。getValue(),
 "评分":this.getView()。byId(" InputRating")。getValue(),
 "价格":this.getView()。byId(" InputPrice")。getValue()
 };

 var oModel = new sap.ui.model.odata.v2.ODataModel(" https://services.odata.org/V2/(S(zgiajht3rj0txzdxqds0itlv))/OData/OData.svc/");

 oModel.create(
 "/产品",
 新数据,
 {
 异步:是的,
 成功:功能(成功){
 alert(" success ..");
 },
 错误:function(oError){
 alert("失败..");
 }
 }
 );
 } 

但是它不起作用。 当我通过运行以下网址对数据进行计数时,数据数保持不变。 https: //services.odata.org/V2/(S(zgiajht3rj0txzdxqds0itlv))/OData/OData.svc/Products/$count

我也尝试了以下功能,但也无法正常工作。

 handleSave:function(){
 var newData = {
 " odata.type":" ODataDemo.Product",
 " ID":this.getView()。byId(" InputID")。getValue(),
 "名称":this.getView()。byId(" InputName")。getValue(),
 "说明":this.getView()。byId(" InputDescription")。getValue(),
 " ReleaseDate":this.getView()。byId(" InputReleaseDate")。getValue(),
 " DiscontinuedDate":this.getView()。byId(" InputDiscontinuedDate")。getValue(),
 "评分":this.getView()。byId(" InputRating")。getValue(),
 "价格":this.getView()。byId(" InputPrice")。getValue()
 };

 var requestObj = {
 requestUri:",
 方法: '',
 标头:{
 " X-Requested-With":" XMLHttpRequest",
 " Content-Type":" application/javascript",
 " DataServiceVersion":" 2.0",
 " MaxDataServiceVersion":" 2.0",
 " Accept":"应用程序/javascript"
 }
 };

 var url =" proxy/http/services.odata.org/V2/(S(zgiajht3rj0txzdxqds0itlv))/OData/OData.svc/";
 var method =" POST";
 requestObj.requestUri = url;
 requestObj.method =方法;
 requestObj.data = newData;
 OData.request(requestObj,function(){
 this.getView()。byId(" idAppControl")。getModel()。refresh();
 this.getView()。byId(" SimpleForm")。setVisible(false);
 });
 } 

请帮助我检查上述两个功能为何不起作用。

还有其他添加新记录的方法吗? 请告知。

4条回答
昵称总是被占用
2020-09-13 01:58 .采纳回答

您的请求的结构与实体集的结构不匹配,没有名称或描述字段。 使用浏览器开发工具查看错误。

此致

Jamie

一周热门 更多>

相关问答