Note - This does not always retun correct results. It works fine if no item is deleted form the list.
Code -
<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(getOldItemid, "sp.js");
function getOldItemid()
{
context = new SP.ClientContext.get_current();
web = context.get_web();
var list = web.get_lists().getByTitle(‘yourlistName’);
var camlQuery = new SP.CamlQuery();
var _query =”<view><query><where></Where></Query><orderby><fieldref Name='Created' Ascending=’FALSE’/></OrderBy></View>";
camlQuery.set_viewXml(_query);
this.listItems = list.getItems(camlQuery);
context.load(listItems, ‘Include(Id,Created)’);
context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod),Function.createDelegate(this, this.onFailureMethod)); }
function onSuccessMethod(sender, args)
{
var count = parseInt(this.listItems.get_count());
if(count >0)
{
var currentItem = listItems[0]; //-> get the first item form Desc order of items
var _ID = currentItem.get_item("Id");// get id of this item.
}
}
function onFaiureMethod(sender, args)
{ }
</script>
Big Thanks to this post for pointers.
Ads by Google
No comments:
Post a Comment