It looks like you have to explicitly load the checkOutType
(and CheckedOutByUser
, if you want it)
varwebSite = clientContext.get_web();
this.list = webSite.get_lists().getByTitle(listname);
this.folder = this.list.get_rootFolder();
this.files = this.folder.get_files();
clientContext.load(this.folder);
clientContext.load(this.files, 'Include(CheckOutType,Name,CheckedOutByUser)');
Try this, from here:
HTML
<!-- Style required for HTML Snippet -->
< style type = "text/css" >
.lst - table th
{
background - color: #ddd;
border: 2 px solid# fff;
text - align: left
}
.lst - table td
{
background - color: #eee;
border: 2 px solid# fff;
}
.web - heading
{
padding: 2 px;
} < /style>
<!--Include jQuery library to perform dynamic html dom manipulation -->
< script type = "text/javascript" src = "/siteassets/jquery.js" > < /script> < div >
< h2 class = "web-heading" > Files with checked - out Status < /h2> < div id = "fldrUrl" > < /div> < /div> < table width = "100%"
cellpadding = "10"
cellspacing = "2"
id = "lstTable"
class = "lst-table" >
< thead >
< tr >
< th > File Name < /th> < th > Checked - out Status < /th> < th > Checked - out By < /th> < /tr> < /thead> < tbody > < /tbody> < /table>
JavaScript
<script type="text/javascript">
functiongetcheckoutStatus(listname)
{
varclientContext = SP.ClientContext.get_current();
if (clientContext != undefined && clientContext != null)
{
varwebSite = clientContext.get_web();
this.list = webSite.get_lists().getByTitle(listname);
this.folder = this.list.get_rootFolder();
this.files = this.folder.get_files();
clientContext.load(this.folder);
clientContext.load(this.files, 'Include(CheckOutType,Name,CheckedOutByUser)');
clientContext.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed));
}
}
functionOnLoadSuccess(sender, args)
{
varfilesEnumerator = this.files.getEnumerator();
$('#fldrUrl').html("Folder URL: " + _spPageContextInfo.webAbsoluteUrl + this.folder.get_serverRelativeUrl());
while (filesEnumerator.moveNext())
{
varcurrentFile = filesEnumerator.get_current();
vartrow = "";
trow += "<tr>";
trow += "<td>" + currentFile.get_name() + "</td>";
if (currentFile.get_checkOutType() < 2)
{
trow += "<td>" + currentFile.get_checkOutType() + " - Yes" + "</td>";
trow += "<td>" + currentFile.get_checkedOutByUser().get_title() + "</td>";
} else {
trow += "<td>" + currentFile.get_checkOutType() + " - No" + "</td>"
trow += "<td></td>";
}
trow += "</tr>";
//Append each list to the table as a row
$("#lstTabletbody").append(trow);
}
}
functionOnLoadFailed(sender, args)
{
try
{
console.log('Error: ' + args.get_message() + '\n' + args.get_stackTrace());
} catch (err) {}
}
functioninjectMethod()
{
getcheckoutStatus("Site Pages");
}
ExecuteOrDelayUntilScriptLoaded(injectMethod, "sp.js");
</script>