I have the following code listed below:
oTable = sap.ui.getCore().byId('tableID');
var index = oTable.getSelectedIndex();
if (index > -1) {
var currentRowContext = oTable.getContextByIndex(index);
var model = oTable.getModel();
var name = model.getProperty("NAME", currentRowContext);
var phase = model.getProperty("PHASE", currentRowContext);
var originalPhase = Phase;
var sequence;
var batchChanges = [];
jQuery.ajax({
type: "GET",
contentType: "application/json",
url: "http://urlpathforxsodata/customer.xsodata/TOOL/?$filter=NAME eq '" + name + "'",
dataType: "json",
async: false,
success: function(data, textStatus, jqXHR) {
// After processing while loop, index will be the
// first non-frozen record
while (originalPhase == phase) {
index = index + 1;
phase = data.d.results[index].PHASE;
}
for (var i = 0; i < index; i++) {
var frozenFlag = data.d.results[i].FROZEN_FLG;
if (frozenFlag != 1) {
sequence = data.d.results[i].SEQUENCE;
var entry = {
NAME: name,
SEQUENCE: sequence,
FROZEN_FLG: 1,
};
batchChanges.push(model.createBatchOperation(
"/TOOL(NAME='" + name + "',SEQUENCE=" + sequence + ")",
"PUT",
entry)
);
}
}
model.addBatchChangeOperations(batchChanges);
// submit changes and refresh the
// table and display message
model.submitBatch(function(data) {
model.refresh();
});
}
});
}
The beginning part of the code is business logic that I've verified to determine which rows I would like to update. I use Ajax to return a data set exactly as what is shown in the table (table cannot be filtered or sorted upon so indices will match). My question is related to the entry and batch calls I am making. It's not working and I'm getting the following order:
POST /FiringOrder.xsodata/TOOL /Services/customer.xsodata/$batch
"2014-11-06 11:26:02 The following problem occurred: HTTP request failed400,Bad Request,{ "error": { "code": "", "message": { "lang": "en-US", "value": "Syntax error in resource path at position 29."}}} - " sap-ui-core.js:80
"2014-11-06 11:26:02 The following problem occurred: HTTP request failed400,Bad Request,{ "error": { "code": "", "message": { "lang": "en-US", "value": "Syntax error in resource path at position 29."}}} - "
Three questions:
- Is there a better way to debug http requests errors? (I'm really new to this sorry!)
- Am I formatting my batch or entry wrong? I have doubts with the URL path I am passing with the parameters (the name and sequence are both keys to the record) and if I should be using PUT to update. Trying MERGE doesn't do anything besides give me a difference error immediately and the error message is unavailable.
- Last but not least, all this logic is in my controller. Is this right or should this type of logic be done on the server?