0

I need to filter result to particular content types fo document library. I cannot seem to retrieve the content type of library. How is this possible. When I try with oList.get_contentTypes() object object is being returned.

function retrieveAllListProperties() {


    var clientContext = new SP.ClientContext();
    var oWebsite = clientContext.get_web();
    this.collList = oWebsite.get_lists();
    clientContext.load(collList);

    clientContext.executeQueryAsync(
        Function.createDelegate(this, this.onQuerySucceeded), 
        Function.createDelegate(this, this.onQueryFailed)
    );
}

function onQuerySucceeded() {
    var listInfo = '';
    var listEnumerator = collList.getEnumerator();

    while (listEnumerator.moveNext()) {
        var oList = listEnumerator.get_current();
        listInfo += 'Title: ' + oList.get_title()  + oList.get_contentTypes() + '\n';
    }
    alert(listInfo);
}
1

oList.get_contentTypes() returns a collection and hence it needs to be iterated to get information about each content type.

UPDATE

var clientContext = new SP.ClientContext.get_current(); 
var oWebsite = clientContext.get_web();
var collList = oWebsite.get_lists();
clientContext.load(collList, 'Include(ContentTypes, Title)');
clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);
function onQuerySucceeded() {
    var listInfo = '';
    var listEnumerator = collList.getEnumerator();
    while (listEnumerator.moveNext()) {
        var oList = listEnumerator.get_current();
        listInfo += 'Title: ' + oList.get_title()  + '\n';
        var ct_enumerator = oList.get_contentTypes().getEnumerator();
        while (ct_enumerator.moveNext()) {
        var ct = ct_enumerator.get_current();
        var contentTypeName = ct.get_name();
        alert(contentTypeName);
    }
    }
    alert(listInfo);
}
function onQueryFailed(sender, args)
{     alert('error'); }
  • Hi doesnt output anything, seems to hang on var ct_enumerator = line. Would it fail if array null ? Does CT need to be expicit Load? – Orange Juice Jones Dec 12 '14 at 10:43
  • Try the updated code. – Nadeem Yousuf Dec 12 '14 at 10:58
  • Thats worked! it shows all the CT's associated with the Library including hierarchy. Not to go on a tangent but is it also possible to exclude empty document libraries? – Orange Juice Jones Dec 12 '14 at 11:19
  • Perhaps open a different question for that. – Nadeem Yousuf Dec 12 '14 at 11:21

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.