1

I'm new to SAP UI5 (Html/JS). I'm currently developing a form for free text item ordering within SRM UI AddOn environment. When the user is done filling the form he clicks the Submit button, the form should disappear and the item should be transferred back to SRM shopping cart. Now I've difficulty implementing the item transfer. I've tried solution in this article (SAPUI5 oModel.create() - how to post data to the SAP backend?) but nothing happens after the code has been executed.

var oParameters = {
    "NEW_ITEM-DESCRIPTION[1]": description,
    "NEW_ITEM-QUANTITY[1]": itemQuantity,
    "NEW_ITEM-UNIT[1]": itemUnit,
    "NEW_ITEM-PRICE[1]": itemPrice,
    "NEW_ITEM-CURRENCY[1]": itemCurrency
};

// use oDataModel.create() to POST free text item to SRM shopping cart
var oDataModel = this.getView().getModel();

// Enable messagebox from jQuery
jQuery.sap.require("sap.ui.commons.MessageBox");

oDataModel.create(hook_url, oParameters, null,
    function() {
        sap.ui.commons.MessageBox.show(sap.ui.commons.MessageBox.alert("Success!"));
    },
    function() {
        sap.ui.commons.MessageBox.alert("Error!");
    }
);

I can manually make an http request (string) combining form location (hook_url) and item information. If I open an empty browser page, paste this string in address bar and hit enter the item would be transferred to shopping cart. I'm wondering if I should use an xml http request in the code to simulate it. Does anyone have a clue how to do it?

Thanks in advance!

Community
  • 1
  • 1
Daniel Xu
  • 23
  • 2
  • What is it the hook_url? Is it right? That first parameter of create method should be the entity where you want to add the new product... For example, if the entity is named "ShoppingCart", the hook_url must have the slash caracter before the entity name: "/ShoppingCart". This works if your oData service is communicating with the SAP netweaver gateway. – solrac Jul 06 '16 at 10:52
  • As Jan Penninkhof mentioned in his answer, you cannot use ODataModel. So no use for `oDataModel.create` – Qualiture Jul 07 '16 at 08:52

1 Answers1

1

The OCI protocol is not based on OData, so you can't use an oDataModel.create to post your data to SRM. Actually, you should not even use XMLHttpRequest, bu use a plain old form post to get your data posted instead. The intention of that form post, is that you also pass browser control back to the SRM application, so that it can redirect the user to the shopping basket.

So, instead of the fancy pancy ODataModels and XMLHTTPRequest, you'll have to go back to the good old form post. You can collate the information in the form using jQuery and UI5 of course.

jpenninkhof
  • 1,920
  • 1
  • 11
  • 12
  • 1
    I was struggling with that too a while ago; in the end, I simply let go of using OData and went with the OCI protocol instead. Submitting the OCI object can be as simple as `$.post(sYourHookURL, oOCIObject).done(doSomething).error(doSomethingElse);` – Qualiture Jul 06 '16 at 10:18
  • Thanks for the answer! Good to hear that i'm not the only one who has struggled for it :). I couldn't believe it was so difficult just to transfer that bit of data. OData looks to be the one as it's a standard communication with backend from SAP... – Daniel Xu Jul 08 '16 at 12:25
  • You're definitely not the only one Daniel. Please also keep in mind that there are almost as many "standards" as product teams. Fortunately many of them are converging to OData, but I think the completely different OCI protocol will be there to stay for quite a while. – jpenninkhof Jul 08 '16 at 13:10