Search code examples
sharepointsharepoint-2010sharepoint-2013ecmascript-5ecma

SharePoint Ecma Get List Properties


I am trying to read a List Properties using SharePoint ECMA but could not success.

Anyone can help - here is the code - tried with method get_fieldValues and get_item and both have returned "undefined".

var key = "vti_level";
function getListProperty() {
    var clientContext = new SP.ClientContext();
    var listGuid = GetUrlKeyValue('List', window.location.href);
    this.props = clientContext.get_web().get_lists().getById(listGuid).get_rootFolder();
    clientContext.load(this.props);
    clientContext.executeQueryAsync(Function.createDelegate(this, getListPropertySuccess), Function.createDelegate(this, getListPropertyFailed));
}

function getListPropertySuccess() {
    var propKey1 = this.props.get_properties().get_fieldValues()[key];
    var propKey2 = this.props.get_properties().get_item(key);
}

function getListPropertyFailed() {
    alert('Request failed on getListProperty.');
}

Solution

  • try this:

        var key = "vti_level";
    
            function getListProperty() {
                var clientContext = new SP.ClientContext();
                var listGuid = _spPageContextInfo.pageListId;
                this.props = clientContext.get_web().get_lists().getById(listGuid).get_rootFolder().get_properties();
                clientContext.load(this.props);
                clientContext.executeQueryAsync(Function.createDelegate(this, getListPropertySuccess), Function.createDelegate(this, getListPropertyFailed));
        }
        function getListPropertySuccess() {
            var propKey1 = this.props.get_fieldValues()[key];
            var propKey2 = this.props.get_item(key);
        }
        function getListPropertyFailed() {
            alert('Request failed on getListProperty.');
        }