2

I'm attempting to access items in a DocumentSet using SharePoint 13's JSOM. I am able to access the generic list properties but I do not see how to access ContentType specific properties on the client side. I have a DocumentSet with PDF's and I need the Name property of the items in the DocumentSet.

function GetContentItem() {
      context = new SP.ClientContext.get_current();
      lstStudents = context.get_web().get_lists().getByTitle('My Asset Library');
      web = context.get_web();
      currentUser = web.get_currentUser();
      context.load(currentUser);
      context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod),
                              Function.createDelegate(this, this.onFailureMethod)); 
    }

function onSuccessMethod(sender, args) {
       var camlQuery = new SP.CamlQuery();

       camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name="Title" /><Value Type="Text">' + getTitle() + '</Value></Eq></Where></Query></View>');
       this.ContentListItems = lstStudents.getItems(camlQuery);
       context.load(ContentListItems);
       context.executeQueryAsync(Function.createDelegate(this, this.showContentData),
                              Function.createDelegate(this,  
       this.onFailureMethod));
    }

//This where I am confused. I do not understand how to access the properties of
//'list' within the DocumentSet

function showContentData()
    {
        var listItemEnumerator = ContentListItems.getEnumerator();
        var mainContainer = document.getElementById('mainContentContainer');

        while (listItemEnumerator.moveNext()) {
            var div = document.createElement('DIV');
            var oListItem = listItemEnumerator.get_current();
            div.innerHTML += 'ID: ' + oListItem.get_id() + 
                'Title: ' + oListItem.get_item('Title');
            div.innerHTML += '<br/>' + oListItem.get_folder();

            mainContainer.appendChild(div);
            }

    }

1 Answer 1

2

The following example demonstrates how to access files in Document Set:

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function() {

    var docSetUrl = '/Documents/2013';  //Document Set named 2013 in Documents library
    var ctx = SP.ClientContext.get_current();
    var ds = ctx.get_web().getFolderByServerRelativeUrl(docSetUrl);
    ctx.load(ds,'Files');
    ctx.executeQueryAsync(
       function () {
           //print file names in Document Set
           for(var i = 0; i < ds.get_files().get_count();i++){
               var file = ds.get_files().get_item(i);
               console.log(file.get_name());  
           }
       },
       function (sender, args) {
          console.log(args.get_message());
       });
});

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.