How to Get\Set Lookup Field using ECMAScript SharePoint 2010
06/15/2011 • Admin
Category: SharePoint 2010
In this post of LearningSharePoint.com we will explain how to get and set a lookup field using Ecmascript use -
Firstly, to get or retrieve a lookup field value see the below example -
function GetLookupValue()
{
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle(‘Testlist’);
var query = SP.CamlQuery.createAllItemsQuery();
allItems = list.getItems(query);
context.load(allItems, ‘Include(Title,Department)’);
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’) + ‘-’ +currentItem.get_item(‘Department’).get_lookupValue() + ‘\n’;
}
alert(TextFiled);
}
function failed(sender, args) {
alert(“failed. Message:” + args.get_message());
}
In the above ECMAScript Department is the Lookup and currentItem.get_item(‘Department’).get_lookupValue() will get you the value of the Lookup item selected.



Recent Forum Posts
Linq to Sharepointby RS on May 18, 2012
comments on the codeby spbsmile on May 18, 2012
connection(add) EditControlBlock and my programby spbsmile on May 18, 2012
Custom master pages used in multiple SharePoint 2010 sitesby ubersteve on May 18, 2012
upload file and click on button but cant upload file into list by using below codeby santhoshreddy on May 18, 2012