Skip to content

Instantly share code, notes, and snippets.

@gokhandemirhan
Forked from wpsmith/file-checkedout-REST.js
Last active September 7, 2015 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gokhandemirhan/f6fa077bc1684cc1b95f to your computer and use it in GitHub Desktop.
Save gokhandemirhan/f6fa077bc1684cc1b95f to your computer and use it in GitHub Desktop.
SharePoint JS: SP.File.checkOutType property gets a value that indicates how the file is checked out of a document library.
//Get file checkout type via CSOM (JavaScript)
var context = SP.ClientContext.get_current();
var web = context.get_web();
var file = web.getFileByServerRelativeUrl(pageUrl);
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());
}
);
//Get file checkout type via REST
$.ajax({url: "/_api/web/getFileByServerRelativeUrl('" + pageUrl + "')/checkOutType",
headers: { "Accept": "application/json; odata=verbose" },
success: function(data) {
if(data.d.CheckOutType == 0) {
console.log('The file is checked out');
}
}
});
function isCheckedOut() {
var isCheckedOut = false;
if (typeof(PageState) != "undefined" && PageState)
{
isCheckedOut = PageState.ItemIsCheckedOutToCurrentUser == "1";
}
if (!isCheckedOut)
{
//do redirect
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment