var batchFilter = [];
for (var i=0;i < companies.length; i++) {
// filter:
// filter: search for tag:c:<name> and has tag "@s:green" + top 1 record order by postdate asc
var company = company[i];
var s = "Posts?$top=1&$skip=0&$orderby=modified desc&$filter=substringof(\'" + company + "\',tags) and " +
" (substringof(\'red\',tags) or substringof(\'@s:yellow\',tags) or substringof(\'@s:green\',tags))";
batchFilter.push(oModel.createBatchOperation(s, "GET"));
}
oModel.addBatchReadOperations(batchFilter);
oModel.submitBatch(....)
This worked and returned back a 200 status code for each record and there were no errors but the data being returned did not match the filter, it was the wrong set of records for each one.
After taking one of the operation urls and plugging it into PostMan this did an HTTP post and returned the data correctly so I was stumped. I opened the Javascript debugging console and went to the Network tab and looked at the data in raw form going up and down the wire to see if there was any issue with that.
I also checked some code I had written on the backend (I was using XS Javascript with XSOdata exits) and there were no problems I could see after all sending the request through postman individually worked but when we put it into a batch request then it failed.
After looking at the above code for a while I eventually realized that there was an old trick I had used for a previous training course where spaces HAVE to be replaced with the + character so that the url can be correctly transported down the wire.
Changing the "s" variable so that all the space characters were replaced caused the data to be filtered correctly.
var batchFilter = [];
for (var i=0;i < companies.length; i++) {
// filter:
// filter: search for tag:c:<name> and has tag "@s:green" + top 1 record order by postdate asc
var company = company[i];
var s = "Posts?$top=1&$skip=0&$orderby=modified desc&$filter=substringof(\'" + company + "\',tags) and " +
" (substringof(\'red\',tags) or substringof(\'@s:yellow\',tags) or substringof(\'@s:green\',tags))";
// now replace the space chars...
s = s.replace(' ', '+');
// and send the final "nice" url
batchFilter.push(oModel.createBatchOperation(s, "GET"));
}
oModel.addBatchReadOperations(batchFilter);
oModel.submitBatch(....)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 |