Skip to Content
0

How to post to a custom url

Jun 20, 2017 at 11:58 PM

53

avatar image

Hello,

I am trying to create a simple application to approve or reject activities. For the purpose I created two function imports (Approve & Reject) in the Data Model of the oData service. I can access these imports successfully via the SAP Gateway Client and I think it all looks good on the server side.

However on my SAP UI5 Application, I am trying to send POST request to any of these services, but it doesn't work:

this.getModel().create("/Approve", oEntry, {

method: "POST",

success: function(data) {sap.ui.commons.MessageBox.alert("Success!");},

error: function() { sap.ui.commons.MessageBox.alert("Error!"); }

});

I see in the debugger that the post request is sent to /$batch instead of /Approve as I expected.

I guess I can use the standard REST Update function in order to accomplish the task, but I'd prefer to find a way to implement it this way.

So does anyone have an idea how can this be done?

Thanks,

Martin

capture.png (8.8 kB)
capture.png (6.3 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Jun Wu Jun 21, 2017 at 12:12 AM
1
Show 3 Share
10 |10000 characters needed characters left characters exceeded

Thank you Jun,

I tried that (also with explicit parameter names with the same result):

var oModel = this.getModel();
oModel.callFunction(
  "/Approve", "GET", {"ACTIVITY_ID": "424242", "NOTE": "test" }, null, 
  function(oData, response) { sap.ui.commons.MessageBox.alert("Success!"); },
  function(oError){ sap.ui.commons.MessageBox.alert("Error!"); }
);

However I get an error in browser console:

I double checked the $metadata of the service, but it looks good to me.

<EntityContainer Name="ZMY_SRV_Entities" sap:supported-formats="atom json xlsx" m:IsDefaultEntityContainer="true">
  <EntitySet sap:content-version="1" Name="ActivitySet" sap:updatable="false" sap:creatable="false" sap:pageable="false" sap:deletable="false" EntityType="ZMY_SRV.Activity"/>
  <FunctionImport Name="Approve" m:HttpMethod="GET" EntitySet="ActivitySet" ReturnType="ZMY_SRV.Activity">
    <Parameter Name="ACTIVITY_ID" Type="Edm.String" Mode="In"/>
    <Parameter Name="NOTE" Type="Edm.String" Mode="In"/>
  </FunctionImport>
</EntityContainer>
<br>

Any idea what am I missing?

Thanks,

Martin

capture.png (5.6 kB)
0
oModel.callFunction(
  "/Approve", {"urlParameters": {"ACTIVITY_ID": "424242", "NOTE": "test" }, "success": 
  function(oData, response) { sap.ui.commons.MessageBox.alert("Success!"); },
 "error": function(oError){ sap.ui.commons.MessageBox.alert("Error!"); }}
);

how about this?

0

I tried that too - there is no difference.

Actually you already answered the initial question, so I will create a new post for this issue as it is a separate topic.

0