ExpandUserField Not Working

Oct 13, 2011 at 1:32 PM
Edited Oct 13, 2011 at 1:35 PM

I was reading in this article that you can pull a user's email from a person field by adding in the following code: "<QueryOptions><ExpandUserField>TRUE</ExpandUserField></QueryOptions>".  It doesn't seem to work for me.

http://sharepointmagazine.net/articles/writing-caml-queries-for-retrieving-list-items-from-a-sharepoint-list

I'm trying to get the last 10 items that have been modified.  There is a person field that should be getting returned with it and I'm assuming it would automatically pull that extra information from that field. 

In the callback function, the status parameter comes back "success" and in the data object status is 200, statusText is "OK" and responseXML.text is an empty string.  The posts variable that this is getting set to will just be undefined.  If I leave the QueryOptions out it will work but it won't get the user's email, which is my ultimate goal (so if there's another way to go about this I'd appreciate that too).  Let me know if you need to know anything else.  

Here's the full code I'm using.  Thanks!

 

var posts = $().SPServices({
            operation: "GetListItems",
            async: false,
            listName: "Leadership News",
            viewName: undefined,
            CAMLViewFields: undefined,
            CAMLQuery: "<Query><OrderBy><FieldRef Name='Modified' Ascending='False' /></OrderBy></Query>",
            CAMLRowLimit: 10,
            CAMLQueryOptions: "<QueryOptions><ExpandUserField>TRUE</ExpandUserField></QueryOptions>",
            completefunc: function (data, status) {
                ajaxCount++;

                if (status === "success") {
                    items = new Array();

                    $(data.responseXML).find("[nodeName='z:row']").each(function () {
                        row = new Array();

                        $(this.attributes).each(function () {
                            row[this.name] = $(this).val();
                        });

                        items[items.length] = row;
                    });
                } else {
                    if (debugConsole) {
                        console.log("getListItems: Syntax Error: unable to lookup lists");
                        console.log(data.responseXML);
                    }
                }

                if (items !== undefined) {
                    if (items.length === 0) {
                        items = undefined;
                    }
                }

                if (async) {
                    asyncComplete(status === "success", items);
                }
            }
        });
Coordinator
Oct 23, 2011 at 3:33 AM

Sorry for the delayed response.

You're passing "undefined" for several of the optinos, which is probably making the cal fail. If you don't want to pass in a value for an option, simply omit it.

In the completefunc, add

alert(xData.responseText);

to see what is returned.

M.