12-08-2016 10:42 PM
Hi Experts!
I´m looking for an option to create dynamically a requestBody object for an odata post.
Example:
Ich have a couple of variables where I'm looking for the field input:
var RepaymentAmount = sap.ui.getCore().byId("RAinput").getValue();
var TermEnd = sap.ui.getCore().byId("Tinput").getValue();
Based on these values I have an requestBody object:
var requestBody = {};
requestBody.Repayment = RepaymentAmount;
requestBody.TermE = TermEnd;
...
oDataModel.create("/LoanCreate", requestBody, ...
But in some product cases the TermEnd is empty, because it will be calculated within the odata service. But if TermEnd value is empty in the object my odata.create runs into an error. To avoid that, my idea is to create the object dynamically. I´ll check whether a value is true or false. So in this example I will not include or delete the "requestBody.TermE" in the object. Is that somehow possible?
Best Regards,
Matthias
12-17-2016 11:38 PM
Hey,
Why not to just add a check to see what's in it and if it's empty replace it with a known value that works in the "create()" method?
In your example:
const emptyConst = 'EMPTY'; //Could be '' as well, as long as you decode it the same all the way
var requestBody = {};
requestBody.Repayment = RepaymentAmount;
TermEnd === null ? requestBody.TermE = emptyConst : requestBody.TermE = TermEnd;
...
oDataModel.create("/LoanCreate", requestBody, ...