Monday 17 October 2011

Get item checked Out to using EcmaScript\Javascript client objetc model


I have earlier blogged about how to get all Checked in or Checked Out Items in a Sharepoint site and also about how to get the Checked Out documents for the current Logged-in user In this post however, I am going to give you an example of how to find out the Checked Out to for a item or in other words how to know the item is checked out to which user using Javascript Object model.
Example -
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle('Testlist');

var query = '<query><where><isnotnull><fieldref lookupid="TRUE" name="CheckoutUser"> </fieldref></isnotnull></where></query>'

var camlQuery = new SP.CamlQuery();

camlQuery.set_viewXml(query);

allItems = list.getItems(camlQuery);

context.load(allItems);

context.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));

function success()
{
var TextFiled = "";
var ListEnumerator = this.allItems.getEnumerator();
while(ListEnumerator.moveNext())
{
var currentItem = ListEnumerator.get_current();
TextFiled += currentItem.get_item('Title')+ 'Checked Out to' + currentItem.get_item('CheckoutUser') '\n';
;
}
alert(TextFiled);
}
function failed(sender, args) {
alert("failed. Message:" + args.get_message());
}

Ads by Google

No comments:

Post a Comment