I am using the Pnp Core library 1.5.0 (https://github.com/pnp/pnpcore) trying to read a lookup value in a sharepoint list.

var listNameBookings = "Bookings";
var itemsBookings = await pnpContext.Web.Lists.GetByTitleAsync(listnameBookings, p => p.Title,
                                                 p => p.Fields.QueryProperties(p => p.InternalName,
                                                                               p => p.FieldTypeKind,
                                                                               p => p.TypeAsString,
                                                                               p => p.Title));

var dict = new Dictionary<string, bool>();
foreach(var d in itemsBookings.Items)
  var Who = (string)d["Who"];
  var When = (DateTime)d["When"];
  var Where = ((IFieldLookupValue)d["Where"]).LookupValue; // ERROR
  dict[Where] = true;

But I get an error when the execution reaches the lookup line:

'((IFieldLookupValue)d["Where"]).LookupValue' threw an exception of type 'PnP.Core.ClientException'

In details Property LookupValue was not yet loaded

Someone knows how to read it?

Thanks you

1 Answer 1

  • For LookUp Field - use below syntax to access the value
 int value = (addedItem["MyField"] as IFieldLookupValue).LookupId;
 string value = (addedItem["MyField"] as IFieldLookupValue).LookupValue;
  • For Multi lookup fields - use below syntax to access the value
 addedItem["MyField"] as IFieldValueCollection).Values

  // Iteration 
  foreach(IFieldLookupValue lookup in (addedItem["MyField"] as IFieldValueCollection).Values)
        // Get the stored lookup id value
        int lookupId = lookup.LookupId; 
  • Thanks you but it does not work: "Property LookupValue was not yet loaded"
    – Piero
    Mar 24 at 10:17

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.