viewName Not Working?

Feb 13, 2015 at 6:08 PM
Hello!

I've been making some headway on a project I startedvearlier this year. If I understand it correctly, I might be able to write less complicated CAML queries by employing views. Unfortunately, I can't seem to figure out how select the specific view SPServices is accessing when I use SPServices.SPGetListItemsJson. It seems to return some facsimile of the default view.

I'm trying to target specific views by feeding it a viewName argument, but the system doesn't seem to be reading this option.

I've tried supplying the name of the view, the GUID, and garbage strings, and it doesn't seem to make any difference. It seems to be entirely ignored and continues to return what looks like the default view, but has some extra columns and doesn't respect the filters in place I've placed on this view.

This is hindering further progress on my project.
Feb 13, 2015 at 8:28 PM
Working through some possible workarounds, I tested the "GetListItems" method with SPServices, it looks like it respects the listName property... but not in SPServices.GetListItemsJson. Kind of a bummer. I much prefer the SPServices.GetListItemsJson way, but it's all I know.
Coordinator
Feb 13, 2015 at 9:09 PM
Michael:

I just checked the code, and viewName ought to be working. Can you post your code?

BTW, I generally discourage relying on views because it's very easy to change one in the UI and cause problems where you don't expect. If you're explicit in the other parameters, you don't really need to use viewName.

M.
Feb 13, 2015 at 9:24 PM
Marc,

Nothing complicated and nothing much to see here...
    var flightListI = $().SPServices({
        operation: "GetListItems",
        async: false,
        listName: "{DB8EAD0C-04B4-4091-AEE2-2FF7EBDDC551}",
        viewName: "{3AA73D31-B663-4657-A953-2DFFC0134DCE}",
        completefunc: function(xData, Status) {
            $(xData.responseXML).SPFilterNode("z:row").each(function() {
                console.log( ($(this).attr("ows_Fighter_x0020_Name")) ); //logs one record :)
                
            });
        }
    });
    
    var flightListII = $().SPServices.SPGetListItemsJson({
        listName: "{DB8EAD0C-04B4-4091-AEE2-2FF7EBDDC551}",
        viewName: "{3AA73D31-B663-4657-A953-2DFFC0134DCE}"
    });

    $.when(flightList).done(function() {
        flightData = this.data; //contains 23 records :(
    });
flightListI uses the specified viewName, which contains one and only one record. flightListII ignores the viewName and returns 23 records. Very frustrating.

I might agree with you that it's better not to rely on the views, but for speed of prototyping, I'd really like to have this working. Any immediate thoughts?
Coordinator
Feb 13, 2015 at 9:39 PM
I see the same thing on my end. I created a new view on my Shared Documents library, set the Item Limit to 2 items. and made this call:
var flightListII = $().SPServices.SPGetListItemsJson({
    listName: "Shared Documents",
    viewName: "test"
});
Instead of 2 items, I got all 7. I'm certain that I'm passing in the viewName (I can see it in the payload), so this could be a bug on the GetListItemChangesSinceToken operation.
https://msdn.microsoft.com/en-us/library/lists.lists.getlistitemchangessincetoken(v=office.12).aspx

M.
Feb 13, 2015 at 9:48 PM
Forgive me, but I don't know what to make of that. Is that to suggest that there's a systemic bug at the MOSS level that can't be overcome here?

Discouraging, but I guess I'll start writing slightly lengthier functions using the ol' SPServices with the GetListItems method.

Thanks for taking the time to test alongside me. Now I don't feel like I'm crazy.
Coordinator
Feb 13, 2015 at 9:58 PM
I think it may be a bug in the Web Services itself, but I'd have to do more testing to be sure.

You can use GetListItems and pass the results through SPXmlToJson if the main reason you like SPGetListItemsJson is because you get JSON back.

M.
Feb 18, 2015 at 3:14 PM
I'm with Marc as well on the CAML approach. If you want an easy button, you could create the views, then export the List Schema. It'll have all of the CAML that you need for your SPServices calls.

http://blog.samlarko.com/2012/08/sharepoint-url-hack-get-list-schema-xml.html

Cheers,
Matthew