This project has moved and is read-only. For the latest updates, please go here.

Batch GetListItems

Jan 22, 2015 at 12:52 PM
Is there a way to pass in a batch of IDs into GetListItems? I have a form where a user enters in an ID and in an onChange event, uses GetListItems to get the data. The problem I am seeing now is once that user is on the 5th row, things slow down to a craw because that's basically the 5th query that's been started. I was thinking of modifying the form so that the user inserts the rows, adds the IDs then clicks a button to query the one time with the entered IDs. Is that possible? Is there a limitation to the number of AND statements in a batch query? Is there another way to do this that I'm missing? Any guidance would be greatly appreciated...
Jan 24, 2015 at 9:18 PM
Yes, this can be done.
Although, I think you want to use OR clauses... :) Saying I want an item ID to be Equal to 1 and Equal to 2 is not going to return you anything.
There is some limit on how "deep" the XML can be (CAML)... but I don't remember now what that is... I hit it once and ended up having to break up my queries and then merge them when they all return the data.
Jan 26, 2015 at 10:00 PM
It's a little hard to picture what you're doing, but Paul's correct in saying that it can be done.

Sometimes it makes more sense to retrieve a greater number of items so that you can make one request rather than many. For instance, if you could retrieve all the items with Color="Red" and the 3 items you need will be in that set, it may be faster than making 3 queries.

Everything depends on your requirements, as always.

Jan 27, 2015 at 2:13 PM
The form in question is designed to manage inventory. The user on any given day will have a random number of containers to sort. The way I designed the form was for the user to insert a row, enter in the inventory ID then on change it would query the table and insert the data. Here is my code:
// OnChange function to insert the original container data
        $(".oc_ShortNo").change(function() {
            var loc = $("#Location").val();

            var row = $(this).closest('tr');
            var waste = row.find("#o_Waste");
            var type = row.find("#o_Type");
            var size = row.find("#o_Size");
            var weight = row.find("#o_oWeight");
            var oType = row.find("#oFormType");
            var var_listName;
            if (loc == 1) {
                var_listName = "v_Inventory_Active_Anaheim";
            } else if (loc == 2) {
                var_listName = "v_Inventory_Active_Baltimore";
            } else if (loc == 6 | loc == 7) {
                var_listName = "v_Inventory_Active_Lancaster";
            } else if (loc == 8) {
                var_listName = "v_Inventory_Active_Trail";
            var shortNo = $(this).val();
            var var_webURL = "webURL"; 
            //var var_listName = "wst_Inventory_Active"; 
            var var_CAMLViewFields = "<ViewFields><FieldRef Name='WID' /><FieldRef Name='ContainerType' /><FieldRef Name='ContainerSize' /><FieldRef Name='Balance' /><FieldRef Name='Net' /><FieldRef Name='FormType' /><FieldRef Name='FormID' /></ViewFields>";
            var var_CAMLQuery = "<Query><OrderBy><FieldRef Name='ID' Ascending='TRUE'></FieldRef></OrderBy><Where><Eq><FieldRef Name='ID' /><Value Type='Integer'>" + shortNo + "</Value></Eq></Where></Query>";
            $.support.cors = true;
                operation: "GetListItems", 
                crossDomain: true,
                webURL: var_webURL,
                async: true, 
                listName: var_listName, 
                CAMLViewFields: var_CAMLViewFields,
                CAMLQuery: var_CAMLQuery,
                CAMLRowLimit: 0,
                completefunc: function (xData, Status) {
                    $(xData.responseXML).SPFilterNode("z:row").each(function() {
The code itself runs beautifully however as I mentioned in the initial post, the form starts to chug after the 4th or 5th row is inserted. I tried constructing an IN CAML query but I couldn't get it to work. Please note that the user could enter anywhere from 5 to 50 rows that need to be sorted. Any point in the right direction would be greatly appreciated!!!
Jan 27, 2015 at 3:38 PM
If it's enter an id, fetch the item with the id, enter an id, fetch the item with the id, etc., then the number of ids shouldn't matter. You're simply doing one request per Id entered, and your user has all the [computing] time in the world between requests.

My suggestion is to debug your code and see where it's getting bogged down. I don't think it's the SPServices calls.