SAPUI5 oModel.create()-如何将数据过帐到SAP后端? [英] SAPUI5 oModel.create() - how to post data to the SAP backend?

查看:122
本文介绍了SAPUI5 oModel.create()-如何将数据过帐到SAP后端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮,可以在其中按新闻方法将数据发布到SAP后端:

I got a button where I want to post data to my SAP backend on press-method:

         oCellBtnOtherchart.addContent(new sap.ui.commons.Button({
             text : "Save",
             press : function() {

                var sServiceUrl = "/MyEntitSet('0001')";

                var oModel = sap.ui.getCore().getModel();
                console.log(oModel);

                 var oParameters = {
                        "email" : "a",
                        "lastname" : "b",
                        "firstname" : "c",
                   };

                oModel.create(sServiceUrl, oParameters);

             }
         }));

我的问题是:

  • 该请求将以哪种方法在后端结束?我希望MyEntitySet_CREATE_ENTITY()
  • 为什么不起作用,错误消息是:HTTP请求失败405,不允许使用方法

但是为什么是405,我的服务URL错误?如何将数据正确发布到SAP后端?

But why is it 405, is my Service URL Wrong? How do I Post data correctly to the SAP Backend?

SAP故障排除指南说:405方法不允许 o资源不允许使用请求行中指定的方法 由Request-URI标识.响应必须包含Allow标头 包含所请求资源的有效方法的列表. ->现在这对我没有帮助,有人知道如何包含allow标头吗?

SAP Troubleshooting Guide says: 405 Method Not Allowed o The method specified in the Request-Line is not allowed for the resource identified by the Request-URI. The response must include an Allow header containing a list of valid methods for the requested resource. --> This does not help me right now, anybody knows how to include an allow header?

推荐答案

由于SO上关于该主题的主题很少,我认为这些主题无法回答我的问题,我将分享如何通过的发现通过oModels创建方法将数据发送到后端:

Because there are only few threads on this topic at SO, which in my opinion do not answer the questions I had, I'll share my findings how to pass data to the backend via oModels create method:

首先定义结果实体的类型(检查oData-Model以了解属性,例如名称和YourID)

First Define a type of your result entity (check your oData-Model to know the attributes, e.g. Name and YourID):

var oEntry = {};
oEntry.YourID = "0001";
oEntry.Name = "Peter";

然后获取您的模型:

var oModel = sap.ui.getCore().getModel();

然后通过以下操作执行创建操作:

Then execute the create operation thanks to: https://sapui5.netweaver.ondemand.com/docs/api/symbols/sap.ui.model.odata.ODataModel.html

jQuery.sap.require("sap.ui.commons.MessageBox");
oModel.create('/EntitySet', oEntry, null, function(){
    sap.ui.commons.MessageBox.show(
         sap.ui.commons.MessageBox.alert("Success!");
     );
    },function(){
      sap.ui.commons.MessageBox.alert("Error!");
});

方法"ENTITYSET_CREATE_ENTITY"-方法中后端的结果,您可以在其中检索您的ID和名称:

Results in Backend in Method "ENTITYSET_CREATE_ENTITY"-Method, where you can retrieve YourID and Name:

DATA: ls_data TYPE ycl_class_mpc=>ts_entity.

CALL METHOD io_data_provider->read_entry_data
  IMPORTING
    es_data = ls_data.

WRITE ls_data-name.
WRITE ls_data-yourid.

此示例适用于单个调用,您可以看到ABAP中的结果是一个结构.如果需要将多个数据集传递到后端,则应在

This example applies to single calls, you can see the result in ABAP is a structure. If you need to pass multiple datasets to the backend you should search for batch processing at https://openui5.hana.ondemand.com/docs/api/symbols/sap.ui.model.odata.ODataModel.html

这篇关于SAPUI5 oModel.create()-如何将数据过帐到SAP后端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆