Date Columns returning all undefined

May 10, 2013 at 1:43 PM
I am working on creating a page in a page viewer that calculates a set of numbers in a table from a list that exists on the site.

I am using GetListItems

I get initial dates from the list. It is a date column and it retrieves the date correctly.
However, when I try and retreive dates that are further in in the list, it gives me all undefineds.

I made sure I had the right static names using the getStaticFromDisplay function. This does retreive the names I am looking for. But, still, when I use these with

someVar = $(this).attr( "ows_" + staticName );

it produces undefined.

I can give more information if need be.
May 10, 2013 at 2:12 PM
Usually, if you're getting undefined for a field that you are referencing correctly, it means the field for the current record doesn't have data in it. The web services call will not return empty fields.

Geoff
May 10, 2013 at 2:55 PM
The columns do have data in them.

My problem, I've realized, is that the default view for the list I'm trying to access doesn't have the desired columns in it. It seems that when I try and access columns that are shown in a different view other than the default, the script can't find them.

Is there a way to specify what view you want data from?

Thanks.
May 10, 2013 at 3:03 PM
Ahhh, that will be an issue as well. Check the documentation for the 'Lists' Services(https://spservices.codeplex.com/wikipage?title=Lists). It provides all of the required/optional parameters for the different 'Lists' operations and a lot of them include examples. Specifying a view in GetListItems is one of those optional parameters.
May 10, 2013 at 3:36 PM
When I try and use the viewName parameter, the status is Error.
I've tried "AllItems" and "All Items".

What could I be doing wrong?
Thanks.


gkoliver wrote:
Ahhh, that will be an issue as well. Check the documentation for the 'Lists' Services(https://spservices.codeplex.com/wikipage?title=Lists). It provides all of the required/optional parameters for the different 'Lists' operations and a lot of them include examples. Specifying a view in GetListItems is one of those optional parameters.
May 10, 2013 at 3:58 PM
The view name must be the GUID of the view, not the friendly name. That is from the MSDN documentation on the GetListItems method. Marc includes those links in the documentation as well because they provide additional, detailed guidance on use and parameters. There is a web service available to get the GUID. I created a short function since I use the viewName feature frequently.
function GetViewGUID(strList, strView) {
// Returns the GUID of view 'strView' of list 'strList'
//  INPUTS:
//      strList: The display name of the list
//      strView: The display name of the view
    var strGUID;
    $().SPServices({
        operation: "GetViewCollection",
        async: false,
        listName: strList, 
        completefunc: function (xData, Status) {
            $(xData.responseXML).SPFilterNode("View").each(function() {
                if($(this).attr("DisplayName") == strView) {
                    strGUID = $(this).attr("Name");
                }
            });
        } 
    }); 
    return strGUID;
}
Coordinator
May 10, 2013 at 4:10 PM
Rather than referencing the view, I just specify the CAMLViewFields or CAMLRowLimit or something. As soon as you specify one of those values, it overrides the default view. In other words, there's zero need to create a view to retrieve what you want - and besides, that view might be changed by someone (usually you!) and break your code.

M.
May 10, 2013 at 5:14 PM
Thanks for all the help. I now have a better grasp of how this all works.

Have a good day.

N.
May 21, 2013 at 8:32 PM
I did not realize that specifying ViewFields or the RowLimit option would override the default view....I learn something new every day and today, I've reached my limit! ;-)