0

I have an app that includes a Document Library...using my normal code to display the list but keep getting a null on the field...i've tried

rptDocsListItem1.get_item("xd_ProgID")

and

rptDocsListItem1.get_item("title")

and

rptDocsListItem1.get_item("Name")

but each of them returns a null?? Am i missing something? Full code below.

// This function shows Country Limits table
function getdocLibrary() {
var rptDocs = document.getElementById("docsList");
rptDocsList = web.get_lists().getByTitle('Document Library');
var camlQuery = SP.CamlQuery.createAllItemsQuery();
var camlQuery = new SP.CamlQuery();
var rptDocsListItems = rptDocsList.getItems(camlQuery);
context.load(rptDocsListItems);
context.executeQueryAsync(

    function () {
        // Success returned from executeQueryAsync

        if (rptDocsListItems.get_count() > 0) {
            var rptDocsListItemEnumerator1 = rptDocsListItems.getEnumerator();

            // Lets get the select items
            while (rptDocsListItemEnumerator1.moveNext()) {
                var rptDocsListItem1 = rptDocsListItemEnumerator1.get_current();
                $("#docsList").append("<li><strong><a href='javascript:;' >" + rptDocsListItem1.get_item("xd_ProgID") + "</a></strong></li>");
            }


            $('#tblDocLibrary').show();

        }
        else { $('#tblNoDocLibrary').show(); $('#tblDocLibrary').hide(); }

    },
    function (sender, args) {
        // Failure returned from executeQueryAsync
        alert("Error in News: " + args.get_message());
    }
    );

}
  • have you loaded the item? – Burrhus Jan 28 '14 at 6:34
  • Yes they are loaded. I did not include all the code...original post updated to reflect this. – Stephen Jan 28 '14 at 9:36
1

How to retrieve properties for Document Library items?

Since some properties are stored in File object, specify File client object explicitly in ClientContext.Load method:

context.load(items,"Include(File)");

then, you could get properties like this:

var file = item.get_file();

var title = file.get_title();
var name = file.get_name(); 

Example

function getDocuments(title) {
   var context = SP.ClientContext.get_current();
   var web = context.get_web(); 

   var docLibrary = web.get_lists().getByTitle(title);
   var items = docLibrary.getItems(SP.CamlQuery.createAllItemsQuery());
   context.load(items,"Include(File)");
   context.executeQueryAsync(
     function () {

        if (items.get_count() > 0) {
            var e = items.getEnumerator();
            while (e.moveNext()) {
                var item = e.get_current();
                var file = item.get_file();

                var title = file.get_title();
                var name = file.get_name();


            }

        }
     },
     function (sender, args) {
        console.log("Error in News: " + args.get_message());
     }
     );
}

getDocuments('Documents');
0

Found the answer...

The following link includes all the "real" column names for a document library, very handy.

Reference list for SharePoint internal field names

The code should read.

rptDocsListItem1.get_item("FileLeafRef")

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.