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 Answers
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.Commented Mar 12, 2014 at 0:20
-
Paul, CSOM example is working properly in both versions (2010/2013),but REST example only in 2013 version. Thank you. Commented Mar 12, 2014 at 8:35
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.– lazoDevCommented Mar 11, 2014 at 19:09
With SPServices, you should be able to use GetListItems and ask that "CheckOutType" (I believe that the internal name) be returned in the output.