The below question was based on this article: http://www.learningsharepoint.com/2011/09/10/get-all-folders-using-ecmascriptjavascript-client-object-model-sharepoint-2010/

I think the author there didnt post all code, because a simple copy and paste Just does not work.

The following code is supposed to query for the folders list in a specific site pages library. I think the problem is in the success method, also I have no idea how to debug .js files in sharepoint? any clue?

But its showing this exception on Internet Explorer status bar: Webpage error details

Update1 I tried this line

context.Load(allItems,'Include(Title, Id)');

But it throws this exception

Object doesn't support this property or method

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E) Timestamp: Mon, 5 Mar 2012 14:41:29 UTC

Message: The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
Line: 5
Char: 62099
Code: 0


COB.SharePoint.Ribbon.PageComponent = function () {

// the initialize function needs to be called by some script added to the page elsewhere - in the end, it does the important work 
// of calling PageManager.addPageComponent()..
COB.SharePoint.Ribbon.PageComponent.initialize = function () {
    ExecuteOrDelayUntilScriptLoaded(Function.createDelegate(null, COB.SharePoint.Ribbon.PageComponent.initializePageComponent), 'SP.Ribbon.js');
COB.SharePoint.Ribbon.PageComponent.initializePageComponent = function () {

    var ribbonPageManager = SP.Ribbon.PageManager.get_instance();
    if (null !== ribbonPageManager) {

COB.SharePoint.Ribbon.PageComponent.prototype = {
    init: function () { },

    getFocusedCommands: function () {
        return ['COB.PageComponent.Command.FieldControl.GroupCommand', 'COB.PageComponent.Command.FieldControl.TabCommand', 'COB.PageComponent.Command.FieldControl.ContextualGroupCommand', 'COB.PageComponent.Command.FieldControl.RibbonCommand'];

    getGlobalCommands: function () {
        return ['COB.PageComponent.Command.DoAction', 'COB.PageComponent.Command.PopulateDropDown', 'COB.PageComponent.Command.QueryDoAction'];

    canHandleCommand: function (commandId) {
        if ((commandId === 'COB.PageComponent.Command.DoAction') ||
            (commandId === 'COB.PageComponent.Command.PopulateDropDown') || (commandId === 'COB.PageComponent.Command.QueryDoAction')) {
            return true;
        else {
            return false;

    handleCommand: function (commandId, properties, sequence) {
        if (commandId === 'COB.PageComponent.Command.FieldControl.GroupCommand') {
            alert("COB.PageComponent.Command.FieldControl.GroupCommand fired");
        if (commandId === 'COB.PageComponent.Command.FieldControl.TabCommand') {
            alert("COB.PageComponent.Command.FieldControl.TabCommand fired");
        if (commandId === 'COB.PageComponent.Command.FieldControl.ContextualGroupCommand') {
            alert("COB.PageComponent.Command.FieldControl.ContextualGroupCommand fired");
        if (commandId === 'COB.PageComponent.Command.FieldControl.RibbonCommand') {
            alert("COB.PageComponent.Command.FieldControl.RibbonCommand fired");
        if (commandId === 'COB.PageComponent.Command.QueryDoAction') {
            // this command executes as soon as tab is requested, so do initialization here ready for if our dropdown gets requested..
        if (commandId === 'COB.PageComponent.Command.PopulateDropDown') {
            // actually build the dropdown contents by setting the PopulationXML property to a value with the expected format. We have to deal with possible 
            // timing issues/dependency on core SharePoint JS code with an ExecuteOrDelay..
            ExecuteOrDelayUntilScriptLoaded(Function.createDelegate(null, getDropdownItemsXml), 'SP.js');

            properties.PopulationXML = getDropdownItemsXml();
        if (commandId === 'COB.PageComponent.Command.DoAction') {
            // here we're using the SourceControlId to detect the selected item, but more normally each item would have a unique commandId (rather than 'DoAction'). 
            // However this isn't possible in this case since each item is a list in the current web, and this can change..
            var selectedItem = properties.SourceControlId.toString();
            var listName = selectedItem.substring(selectedItem.lastIndexOf('.') + 1);
            alert("You selected the list: " + listName);

    isFocusable: function () {
        return true;

    receiveFocus: function () {
        return true;

    yieldFocus: function () {
        return true;

// **** BEGIN: helper code specific to this sample ****

// some global variables which we'll use with the async processing..
// var lists = null;
var querySucceeded = false;

// use the Client Object Model to fetch the lists in the current site..        
function loadCurrentWebLists() {
    var clientContext = new SP.ClientContext.get_current();
    var web = clientContext.get_web();
    this.lists = web.get_lists();

           Function.createDelegate(this, this.onQuerySucceeded),
           Function.createDelegate(this, this.onQueryFailed));

var allItems;

function GetFolders() {
    var context = new SP.ClientContext.get_current();
    var web = context.get_web();
    var list = web.get_lists().getByTitle('Site Pages');
    var query = SP.CamlQuery.createAllFoldersQuery();
    allItems = list.getItems(query);
    //context.Load(allItems, 'Include(Id, DisplayName)');
    context.load(allItems, 'Include(Id, DisplayName)');

    context.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));

function success() {
    var FolderNames = "";
    var ListEnumerator = this.allItems.getEnumerator();
    while (ListEnumerator.moveNext()) {
        var currentItem = ListEnumerator.get_current();
        var context = new SP.ClientContext.get_current();
        var _contentType = currentItem.get_fileSystemObjectType();
        if (currentItem.get_fileSystemObjectType() == '1') {
            FolderNames += currentItem.get_displayName() + '\n';

function failed(sender, args) {
    alert("failed. Message:" + args.get_message());

function onQuerySucceeded() {
    querySucceeded = true;

function onQueryFailed(sender, args) {
    querySucceeded = false;

function getDropdownItemsXml() {
    var sb = new Sys.StringBuilder();
    sb.append('<Menu Id=\'COB.SharePoint.Ribbon.WithPageComponent.PCNotificationGroup.Dropdown.Menu\'>');
    sb.append('<MenuSection DisplayMode=\'Menu\' Id=\'COB.SharePoint.Ribbon.WithPageComponent.PCNotificationGroup.Dropdown.Menu.Manage\'>');
    sb.append('<Controls Id=\'COB.SharePoint.Ribbon.WithPageComponent.PCNotificationGroup.Dropdown.Menu.Manage.Controls\'>');
    if (querySucceeded) {
        var listEnumerator = lists.getEnumerator();

        while (listEnumerator.moveNext()) {
            var oList = listEnumerator.get_current();

            sb.append(' Id=\'COB.SharePoint.Ribbon.WithPageComponent.PCNotificationGroup.Dropdown.Menu.Manage.');
            sb.append(' Command=\'');
            sb.append(' LabelText=\'');
    return sb.toString();

// **** END: helper code specific to this sample ****

COB.SharePoint.Ribbon.PageComponent.registerClass('COB.SharePoint.Ribbon.PageComponent', CUI.Page.PageComponent);
COB.SharePoint.Ribbon.PageComponent.instance = new COB.SharePoint.Ribbon.PageComponent();
  • I tested your code. It works fine for me. So it must be something else. Mar 5, 2012 at 15:26
  • I updated the question with all code of the .JS, any idea what should I look for?, when I use the method loadCurrentWebLists it WORKs Mar 5, 2012 at 15:47
  • The 'Object doesn't support this property or method' is VERY generic - it means that youre trying to call a method or property that doesn't defined. It will be much easier to help if you debug your code in IE Developer toolbar for example and tell us what's the method/property that's undefined.
    – Alex Boev
    Mar 5, 2012 at 15:53
  • And I still strongly insist that a page component is unnecessary complex for your task - the simple command handler with the function call is enough.
    – Alex Boev
    Mar 5, 2012 at 16:42
  • can you please provide an example? do you mean put the js code in the elements.xml file embedded? Why? Actually I like to separate the files, I think maintenance is easier/! Mar 6, 2012 at 16:01

2 Answers 2


This error means that you are trying to get some property that you didn't request explicitly. Maybe it's the Title field you're trying to use. Look at the example from here:

       function retrieveListItems() {

        var clientContext = new SP.ClientContext('/sites/MySiteCollection');
        var oList = clientContext.get_web().get_lists().getByTitle('My List');

        var camlQuery = new SP.CamlQuery();
        camlQuery.set_viewXml('<View><Query><Where><Leq>' + 
            '<FieldRef Name=\'ID\'/><Value Type=\'Number\'>100</Value>' + 

        this.collListItem = oList.getItems(camlQuery);

        clientContext.load(collListItem, 'Include(Id, DisplayName)');

        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();


function onQueryFailed(sender, args) {

    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());

It's the way to tell client object model what fields do you want. The interesting part of this example is:

clientContext.load(collListItem, 'Include(Id, DisplayName)');
  • that syntax is .net, not javascript, searching I tried this context.Load(allItems,'Include(Title, Id)'); but now it says Object doesn't support this property or method @Alex Boev Mar 5, 2012 at 15:11
  • Oops, I didn't notice that I get the wrong example from that page. I've updated the answer.
    – Alex Boev
    Mar 5, 2012 at 15:20
  • Please see the updated question, I tried to do the same, but I still get the exception. I just cant find any difference. Mar 5, 2012 at 15:39
  • I have updated ALL the code of the .JS file. Mar 5, 2012 at 15:45

try with get_id() instead of get_item('Id');

var oItem ='';
function retrieveWebSite() {
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function(){
        var clientContext = new SP.ClientContext.get_current();
        this.oWebsite = clientContext.get_web();

        var lstObject = oWebsite.get_lists().getByTitle('Listname');
        oItem = lstObject.getItemById(5);

            Function.createDelegate(this, this.onQuerySucceeded), 
            Function.createDelegate(this, this.onQueryFailed)       

function onQuerySucceeded(sender, args) {
    var look  = oItem.get_item('LookupColumnName').get_lookupValue();
    var title = oItem.get_item('Title');
    var id = oItem.get_id();
    alert("Loook up column value: "+look);
    alert("Title column: "+title);
    alert("Id column value: "+id);

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

Your Answer

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

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