Search This Blog

Saturday, March 18, 2017

How to retrieve associated list name from a FieldLookupValue Sharepoint 2013 CSOM

The following example demonstrates how to retrieve associated List for Predecessors field from Tasks list:

using (var oClientContext = new ClientContext("http://Testserver/sites/Test"))
{
     var list = oClientContext.Web.Lists.GetByTitle("Tasks");
     var field = list.Fields.GetByInternalNameOrTitle("Predecessors");
     var lookupField = oClientContext.CastTo<FieldLookup>(field);
     oClientContext.Load(lookupField);
     oClientContext.ExecuteQuery();
     var lookupListId = new Guid(lookupField.LookupList); //returns associated list id
     //Retrieve associated List
     var lookupList = oClientContext.Web.Lists.GetById(lookupListId);
     oClientContext.Load(lookupList);
     oClientContext.ExecuteQuery();
}

No comments:

Post a Comment