0

Today i ran into this issue, simply described:

I have a SharePoint custom list where I have added a custom button in the it's ribbon, this button pops up a custom ASPX modal dialog, this dialog only contains an ASP dropdown and a button, se screenshot below:

enter image description here

What I'm willing to achieve is to retrieve all values of for example the "Title" list column, and populate those values into the dialog's dropdown. Se script below:

$(window).bind("load", function () {
    var container = new Array(),
        i = 0;
    $().SPServices({
        operation: "GetListItems",
        listName: "Project review",
        webUrl: "/internal/lists/project%20review",
        async: false,
        CAMLQuery: "<Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'></Value></Eq></Where></Query>",
        CAMLViewFields: "<ViewFields>" + "<FieldRef Name='Title' />" + "</ViewFields>",
        completefunc: function (xData, ID) {
            $(xData.responseXML).find('z\\:row, row').each(function () {
                container[i++] = $(this).attr("ows_Title");
                alert(container);
                for (var i = 0; i < container.length; i++) {
                    var opt = container[i];
                    var option = document.createElement("option");
                    option.textContent = opt;
                    option.value = opt;
                    var toDropDown = document.getElementById("managers_list");
                    toDropDown.appendChild(option);
                }
            });
        }
    });
})

The script does unfortunately not do my purpose, anyone who could shed some light upon this issue?

Thanks in advance!

2
  • 1
    Try getting rid of the webUrl and CAMLQuery options. And depending on your version of spservices, you should be using SPFilterNode instead of .find. Commented Jan 28, 2015 at 19:15
  • Thanks! Your hints helped, I had also to use: completefunc: function(xData, Status) {xData.responseXML} instead of: completefunc: function(xData, ID) {xData.responseText} in order to get it working. For the xData.responseXml i understand why, but not really why I had to use Status instead of ID, any idea? Commented Jan 30, 2015 at 8:59

1 Answer 1

1

Try this code

$(document).ready(function(){
    $().SPServices({
        operation: "GetListItems",
        listName: "Project review",
        webUrl: "/internal/",
        async: false,
        CAMLQuery: "<Query><Where><Gt><FieldRef Name='Id'/><Value Type='Number'>0</Value></Gt></Where></Query>",
        CAMLViewFields: "<ViewFields>" + "<FieldRef Name='Title' />" + "</ViewFields>",
        completefunc: function (xData, ID) {
            $(xData.responseXML).find('z\\:row, row').each(function () {
                $('#managers_list').append("<option>" + $(this).attr("ows_Title") + "</option>");
            });
        }
    });
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.