Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Paul_todd
Product and Topic Expert
Product and Topic Expert


Recently I had quite a complex query I needed to run over multiple dimensions so the most efficient way to do this was to create multiple OData Queries and put them into a batch.

 

The code looked like:

 

     var oModel = sap.ui.getCore().getModel("LEDGER");

     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 oModel = sap.ui.getCore().getModel("LEDGER");

     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(....)


 

So my tale of woe had a a happy ending and the report started working successfully, amazing how one little assumption can cause so many problems


  • SAP Managed Tags: