Learning SharePoint   Enhance Your SharePoint Knowledge

Subscribe to Learning SharePoint Subscribe
Twitter Learning SharePointFollow Us
in Learning SharePoint
Check Out Our New SharePoint 2013 series!

Get item version Ecmascript client object model SharePoint 2010

07/03/2011  
Category: SharePoint 2010


Here is a short example about how to retrieve the current version if an item using EcmaScript\Javascript client object model.

<script type=”text/ecmascript”>

ExecuteOrDelayUntilScriptLoaded(GetVersions, “sp.js”);

function GetVersions()
{

var context = new SP.ClientContext.get_current();

var web = context.get_web();

var list = web.get_lists().getByTitle(“List name”);

var query = ‘<View><Query><Where><Eq><FieldRef Name=”Title” /><Value Type=”Text”>test title</Value></Eq></Where>
</Query><ViewFields><FieldRef Name=”Title” /></ViewFields></View>’;

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 VersionInfo = “”;

var ListEnumerator = this.allItems.getEnumerator();

while(ListEnumerator.moveNext())
{
var currentItem = ListEnumerator.get_current();
var context = new SP.ClientContext.get_current();
context.load(currentItem);
context.executeQueryAsync(
function(sender,args)
{
VersionInfo  = currentItem.get_item(“_UIVersionString”);
alert(VersionInfo);
},

function (sender, args)
{
showError(args.get_message());
});
}}

See all the Fields – Get various item fields using Client Object Model Ecmascript

Subscribe to Learning SharePoint Subscribe
Twitter Learning SharePointFollow Us
in Learning SharePoint
Advertisement

Random Posts

.Net 4 with SharePoint Foundation 2010
.Net 4 with SharePoint»

Since this has been asked a million times in various forums. Here is the Final word from Michael Foertsch (secretsofsharepoint.com/cs).»

Delete Custom Content Type in Sharepoint
Delete Custom Content Type»

Here is the solution for deleting a custom Content type. 1. Go Site Actions> Modify All Site Settings: 2. Go»

Tools used for Unit Testing SharePoint 2010
Tools used for Unit»

Once you ’ ve done some smoke testing on your dev machine, it is important to perform more formal testing»

Recent Forum Posts

Linq to Sharepoint

by RS on May 18, 2012

comments on the code

by spbsmile on May 18, 2012

connection(add) EditControlBlock and my program

by spbsmile on May 18, 2012

Custom master pages used in multiple SharePoint 2010 sites

by ubersteve on May 18, 2012

upload file and click on button but cant upload file into list by using below code

by santhoshreddy on May 18, 2012