1

I have the following script that is returning the error message "list.getItemByID is not a function" and I can't figure out why. All examples use this function. I am trying to iterate through thumbnails on a page and then load the list they are from and get additional information for each thumbnail. Just to test I am trying to just show the titles in an alert at this point.

ExecuteOrDelayUntilScriptLoaded(getMyList, "SP.js");

function getMyList() {

    var listTitle = 'Faces'
    var ctx = SP.ClientContext.get_current();
    var web = ctx.get_web();
    var lists = web.get_lists();
    var list = lists.getByTitle(listTitle);


    var items = [];
    var elements = document.getElementsByClassName('ms-tileview-tile-detailsBox');

    for (var i = 0; i < elements.length; i++) {
        var title = elements[i].getAttribute("id");
        var id = title.substring(10, GetSubstringIndex(title, "_", 3));
        var item = list.sp.getItem
        items.push(item);
        ctx.load(item, "Title");
    };
    if (items) {
        ctx.executeQueryAsync(function () {

            var titles = "Titles of the selected items:\n";
            for (var j = 0; j < items.length; j++) {
                titles += items[j].get_item("Title") + "\n";
            }
            alert(titles);
        }, function (sender, args) {
            alert('Request failed. '
                + args.get_message() + '\n'
                + args.get_stackTrace());
        });
    };
};


function GetSubstringIndex(str, substring, n) {
    var times = 0, index = null;

    while (times < n && index !== -1) {
        index = str.indexOf(substring, index + 1);
        times++;
    }

    return index;
};

  • The above code has the ID of the item requested hard coded just to test. In theory it would look up the thumbnail's id that is calculated but again- jus testing. – Roo Jul 17 '15 at 20:17
  • have you tried getItemById ? with a small d in Id? – Gwny Jul 20 '15 at 14:08
  • As @Gwny stated, the last letter is lower case. JavaScript is case-sensitive, and as seen in this MSDN page, the method is getItemById(). – wjervis Jul 21 '15 at 12:48
0

You have a capital D on list.getItemByID, it should be list.getItemById

https://msdn.microsoft.com/en-us/library/office/jj246019.aspx

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.