UpdateListItems Only Updates the First Record

May 29, 2013 at 3:18 PM
I'm running a script that enumerates the folders of a list. For each folder, I look up it's existing name in another list, return the new name from the second list and update the folder name to the new name returned. The lookups/returns are working fine. I want the folder "Title" and "BaseName" to change to the new name returned. Strangely, it succeeds completely for the first folder it attempts to update. However, subsequent folders only change their "Title" while the "BaseName" remains unchanged. I have tried several different methods and keep getting the same results. The returned XML for each UpdateListItem operation doesn't indicate any errors. Here's a snippet of what I'm doing:
    //Enumerate the folders of the target list
    $().SPServices({
        operation: "GetListItems",
        async: false,
        listName: "UserMessages,   //defalt view is by folder
        CAMLViewFields: "<ViewFields Properties='True' />",
        CAMLQuery: "<Query><Where><Eq><FieldRef Name='FSObjType' /><Value Type='Integer'>1</Value></Eq></Where></Query>",
        CAMLQueryOptions: "<QueryOptions><IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns></QueryOptions>",
        completefunc: function(xData, Status) {
            //I've confirmed the GetListItems oop returns a list of folders
            $(xData.responseXML).SPFilterNode("z:row").each(function() {
                strWPUserName = $(this).attr("ows_Title");
                lngUserMsgFolderID = $(this).attr("ows_ID");
                strAFNetUsername = $(xmlAFNetCrossRef).find("[ows_WPUserName=" + strWPUserName + "]").attr("ows_AFNetUserName");   //This is the lookup to the second list (stored XML)--it works
                if(strAFNetUsername != undefined) {
                    //console.log(strWPUserName + " = " + strAFNetUsername);
                    //This operation updates "Title" and "BaseName" for the first record, only updates "Title" for each record after that(?????)
                    $().SPServices({
                        operation: "UpdateListItems",
                        async: false,
                        batchCmd: "Update",
                        listName: strListUpdate,
                        valuepairs: [["Title", strAFNetUsername], ["BaseName", strAFNetUsername]],
                        ID: lngUserMsgFolderID,
                        completefunc: function(xData, Status) {
                            console.log(xData.responseText);
                        }
                    });
                }
            });
        alert("Completed updates");
        }
    });
I've run out of ideas.....
Jun 3, 2013 at 6:22 PM
OK, I've done some more testing and it gets weird. I figured out the only item it will update in a series is the first item, which happens to have an ID of 1. So, breaking it down to its simplest form, I created a short script and attempted to update other folders one at a time.
function UpdateUserMsgFolders() {
    $().SPServices({
        operation: "UpdateListItems",
        async: false,
        batchCmd: "Update",
        listName: "UserMessages",
        valuepairs: [["Title", "9999999999c"], ["BaseName", "9999999999c"]],
        ID: 4,
        completefunc: function(xData, Status) {
            console.log(xData.responseText);
        }
    });
    alert("Completed updates");
}
As long as the ID is 1 (and there is a folder with the ID of 1), everything works fine. If I choose the ID of any other existing folder, the 'Title' changes for the selected folder but the 'BaseName' does not. Does this make sense to anyone?

Thanks,
Geoff
Coordinator
Jun 4, 2013 at 3:46 PM
Geoff:

I'm not sure one this one. Let us know what else you find...

M.
Jun 4, 2013 at 9:19 PM
And the weirdness continues.....
I've learned that the SPServices function works as advertised on all folders in a Document Library. However, in a list that isn't a document library, you can only change the 'BaseName' field for a folder whose ID=1. This is very odd behavior but I have tested it about 50 different ways, including building my own $.ajax call from scratch (bypassing SPServices) and getting the same results all around. It boggles the mind...

Geoff