Preaching SharePoint

How to get Lookup field value client Object Model SharePoint


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.



Responses

0 Respones to "How to get Lookup field value client Object Model SharePoint"

Post a Comment

 

Do you want SharePoint 2013 to inherit Metro Style design?

Search This Blog

Return to top of page Copyright © 2010 | Platinum Theme Converted into Blogger Template by HackTutors