3

I was wondering if anyone knew how to tell if an item has been checked in or out from SPServices? I am able to get all of the nodes but I do not see one which captures the checkout. Is there a way to do this with SPServices, or maybe with the client-object model?

3

You could use SP.File.checkOutType property to determine whether document is checked out of a document library

REST

$.ajax({url: "/_api/web/getFileByServerRelativeUrl('" + docUrl  + "')/checkOutType",
        headers: { "Accept": "application/json; odata=verbose" }, 
        success: function(data) {
                  if(data.d.CheckOutType == 0) {
                        console.log('The file is checked out');
                  }
               }
});

CSOM (JavaScript)

var context = SP.ClientContext.get_current();
var web = context.get_web();
var file = web.getFileByServerRelativeUrl(docUrl);
context.load(file);

context.executeQueryAsync(
     function(){
         if(file.get_checkOutType() == SP.CheckOutType.online) {
                        console.log('The file is checked out');
         }    
      },
      function(sender, args){    
          console.log(args.get_message());
      }
);
  • Vadim, although not a SPservices approach, it's a great response. Thank you. Do you know if this works in SP2010 as well as SP2013? (I know SP2007 is out of the question) – Paul T. Mar 12 '14 at 0:20
  • Paul, CSOM example is working properly in both versions (2010/2013),but REST example only in 2013 version. Thank you. – Vadim Gremyachev Mar 12 '14 at 8:35
0

Not sure if there is any method to know file is checked out using SPServices. But still as a tweak what i can suggest is try getting value of 'CheckoutUser' column of that particular document. If value for that field is null or empty you can assume it is not checked out(ie Checked in).

document.get_item('CheckoutUser');

Here document is SPListItem object from document library.

Hope this helps..!!

  • I looked into this field when I was trying to findout which one I could use for my logic. It seems as if SharePoint caches this information because once I checked it out and checked it back in, there were never any null values. It still had my name under this z:row node. – lazoDev Mar 11 '14 at 19:09
0

With SPServices, you should be able to use GetListItems and ask that "CheckOutType" (I believe that the internal name) be returned in the output.

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.