0

I'm following a code sample from msdn to get properties of items from a list. My announcements list has 2 items. But for some reason I get an exception while getting the enumerator (TypeError: collListItem.getEnumerator is not a function var listItemEnumerator = collListItem.getEnumerator();). Any Idea why this might be happening?

function retrieveListItemsInclude() {
    var clientContext = SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('Announcements');

    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><RowLimit>100</RowLimit></View>');
    var collListItem = oList.getItems(camlQuery);

    clientContext.load(
        collListItem,
        'Include(Id, DisplayName, HasUniqueRoleAssignments)'
    );
    clientContext.executeQueryAsync(function onQuerySucceeded(collListItem) {
        var listItemInfo = '';
        var listItemEnumerator = collListItem.getEnumerator();

        while (listItemEnumerator.moveNext()) {
            var oListItem = listItemEnumerator.get_current();
            listItemInfo += '\nID: ' + oListItem.get_id() +
                '\nDisplay name: ' + oListItem.get_displayName() +
                '\nUnique role assignments: ' +
                oListItem.get_hasUniqueRoleAssignments();
        }

        alert(listItemInfo.toString());
    }, function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() +
            '\n' + args.get_stackTrace());
    }
    );
}
2

Try this, it's the same as your code, but moved the success/fail handlers outside as functions:

var collListItem;

function retrieveListItemsInclude() {
    var clientContext = SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('Announcements');

    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><RowLimit>100</RowLimit></View>');
    collListItem = oList.getItems(camlQuery);

    clientContext.load(
        collListItem,
        'Include(Id, DisplayName, HasUniqueRoleAssignments)'
    );
    clientContext.executeQueryAsync(
        Function.createDelegate(this, this.onQuerySucceeded),
        Function.createDelegate(this, this.onQueryFailed)
    );
}

function onQuerySucceeded(sender, args) {
    var listItemInfo = '';
    var listItemEnumerator = collListItem.getEnumerator();

    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        listItemInfo += '\nID: ' + oListItem.get_id() +
            '\nDisplay name: ' + oListItem.get_displayName() +
            '\nUnique role assignments: ' +
            oListItem.get_hasUniqueRoleAssignments();
    }

    alert(listItemInfo.toString());
}
function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() +
        '\n' + args.get_stackTrace());
}
  • This should solve your problem. Gotta watch your nested constructors. – Brandon C. Jun 12 '14 at 14:41

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.