6

Is there a way to get all the checked-out documents in a library? I know this cannot be done by search-driven webparts, but is there a way let's say through REST or something like that?

4

I can suggest 3 ways to achieve this:

First 2 are REST and Javascript:

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());
      }
);

Third one is the easiest based on Spservices:

SpServices

Use SpServices GetListItems and write a query where you search for all the items where "CheckOutType"("checkedOutTo" please check the internal name) is not null. You can then iterate through all the items.

Do let me know if you need help writing the query. Cheers!

  • Do I Need a list of documents in the first 2 approaches? – yngrdyn Jul 13 '15 at 13:09
  • Yes these are just reusable functions. You'll need to iterate over the library and check if that document is checked out or not. The advantage of it is that you'll have list off all checked out documents in the end. – Taran Goel Jul 13 '15 at 13:16
  • yes, but what about the performance? – yngrdyn Jul 13 '15 at 13:23
  • Can you add an example for the third approach, SpServices with a query? Thanks. – zed Apr 13 '18 at 3:45
1

You can try something like this:

var thaUrl = "<app web url>/_api/web/lists/GetByTitle('<library>')//CheckOutType';
jQuery.ajax({
    type: "POST",
    headers: {
        "Accept": "application/json;odata=verbose",
        "X-RequestDigest": $("#__REQUESTDIGEST").val()
    },
    contentType: 'application/json',
    url: thaUrl,
    success: function (data) {
        //whatever you want to do if success
    },
    error: function (err) {
        alert('Error, I explode :(');
    },
    complete: function (item) { }
});

This will return all the files state in a library. Where:

CheckOutType values: Online = 0; Offline = 1; None = 2.
0

This worked great for me!

_api/web/lists/getByTitle('ListTitle')/items?$select=*,File&$expand=File

You'll get a return inline that contains CheckOutType for all Documents

<content type="application/xml">
<m:properties>
<d:CheckInComment />
**<d:CheckOutType m:type="Edm.Int32">0</d:CheckOutType>**
<d:ContentTag>{388E63ED-C38A-4660-AE30-97AB6A4834D1},3,6</d:ContentTag>
<d:CustomizedPageStatus m:type="Edm.Int32">0</d:CustomizedPageStatus>

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.