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!

  • 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. – Eric Alexander Jan 28 '15 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? – Eliya Amanoeel Jan 30 '15 at 8:59
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, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.