function getcheckoutStatus(listname, itemid)
{
var clientContext = SP.ClientContext.get_current();
if (clientContext != undefined && clientContext != null)
{
var webSite = clientContext.get_web();
this.list = webSite.get_lists().getByTitle(listname);
this.item = list.getItemById(itemid);
this.file = this.item.get_file();
clientContext.load(this.file, 'CheckOutType', 'Name', 'CheckedOutByUser');
clientContext.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed));
}
}
function OnLoadSuccess(sender, args)
{
if (this.file.get_checkOutType() < 2) console.log(this.file.get_name() + " is checked out by " + this.file.get_checkedOutByUser().get_title());
else console.log(this.file.get_name() + " is not checked out.");
}
function OnLoadFailed(sender, args)
{
try
{
console.log('Error: ' + args.get_message() + '\n' + args.get_stackTrace());
}
catch (err)
{}
}
function injectMethod()
{
getcheckoutStatus("Site Assets", 4);
}
ExecuteOrDelayUntilScriptLoaded(injectMethod, "sp.js");This snippet helps to get the check-out status of the given SharePoint t file item using ecmsScript.
