3

I have code here,

    clientContext.load(collListItem, 'Include(Id, Fruits)');
    clientContext.executeQueryAsync(
        Function.createDelegate(this, this.onQuerySucceeded),
        Function.createDelegate(this, this.onQueryFailed)
    );

function onQuerySucceeded(sender, args) {
    var listItemInfo = '';
    var listItemEnumerator = collListItem.getEnumerator();

    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();

        listItemInfo += '\nID: ' + oListItem.get_id() + '\nFruits: ' + ???;

how can I get all values of Fruit as fruit is a custom field.?

5

It depends whether Lookup Field is multi-valued or single-valued.

How to retrieve Lookup field via CSOM in SharePoint 2013

SP.LookupField value is represented as SP.FieldLookupValue object:

//Get LookupField value
var categoryValue = item.get_item('Category');
var catLabel = categoryValue.get_lookupValue();
var catId = categoryValue.get_lookupId();

Multiple SP.LookupField value is represented as array of SP.FieldLookupValue

//Get Multiple Lookup Field value
var categoryValues = item.get_item('Categories'); 
for(var i = 0; i < categoryValues.length; i++) {
   var categoryValue = categoryValues[i];
   var catLabel = categoryValue.get_lookupValue();
   var catId = categoryValue.get_lookupId();
}
4

Use oListItem.get_item('Fruits').get_lookupValue() where Fruits is the internal name of the field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.