We have
- a SharePoint 2013 document library
- a custom content type added to the library, based on standard "Folder" content type; a new "DisplayName" text field added to the content type
- a few folders of that custom content type were created in the document library
I try to make a JavaScript control to visualize folder structure from the library. But I can't get the custom "DisplayName" field value
this.clientContext = SP.ClientContext.get_current();
var web = this.clientContext.get_web();
this.clientContext.load(web);
this.clientContext.executeQueryAsync(function(sender, args) {
for (var i = 0; i < this.topLevelFoldersUrl.length; i++) {
var contextParams = {};
contextParams.folderUrl = web.get_serverRelativeUrl() + "/" + this.topLevelFoldersUrl[i];
// folder
contextParams.topLevelFolder = web.getFolderByServerRelativeUrl(contextParams.folderUrl);
this.clientContext.load(contextParams.topLevelFolder, 'Include(DisplayName)');
// folder list item
contextParams.folderListItem = contextParams.topLevelFolder.get_listItemAllFields();
this.clientContext.load(contextParams.folderListItem);
// subfolders
contextParams.folderCollection = contextParams.topLevelFolder.get_folders();
this.clientContext.load(contextParams.folderCollection);
this.clientContext.executeQueryAsync(
function (sender, args) {
var folderName = contextParams.topLevelFolder.get_name();
// EXCEPTION goes here: "property has not been initialized"
var folderDisplayName = contextParams.folderListItem.get_item("DisplayName");
// visualization code...
},
this.onQueryFailed
);
}
}, this.onQueryFailed);
Is there a special technique to get folder custom fields? I've googled all the code samples to get list items and their custom fields, but the samples don't work in my case.