Get Checked-Out Status of the File in SharePoint

  1. function getcheckoutStatus(listname, itemid)  
  2. {  
  3.     var clientContext = SP.ClientContext.get_current();  
  4.     if (clientContext != undefined && clientContext != null)  
  5.     {  
  6.         var webSite = clientContext.get_web();  
  7.         this.list = webSite.get_lists().getByTitle(listname);  
  8.         this.item = list.getItemById(itemid);  
  9.         this.file = this.item.get_file();  
  10.         clientContext.load(this.file, 'CheckOutType''Name''CheckedOutByUser');  
  11.         clientContext.executeQueryAsync(Function.createDelegate(thisthis.OnLoadSuccess), Function.createDelegate(thisthis.OnLoadFailed));  
  12.     }  
  13. }  
  14.   
  15. function OnLoadSuccess(sender, args)  
  16. {  
  17.     if (this.file.get_checkOutType() < 2) console.log(this.file.get_name() + " is checked out by " + this.file.get_checkedOutByUser().get_title());  
  18.     else console.log(this.file.get_name() + " is not checked out.");  
  19. }  
  20.   
  21. function OnLoadFailed(sender, args)  
  22. {  
  23.     try  
  24.     {  
  25.         console.log('Error: ' + args.get_message() + '\n' + args.get_stackTrace());  
  26.     }  
  27.     catch (err)  
  28.     {}  
  29. }  
  30.   
  31. function injectMethod()  
  32. {  
  33.     getcheckoutStatus("Site Assets", 4);  
  34. }  
  35. ExecuteOrDelayUntilScriptLoaded(injectMethod, "sp.js");