0

I have a lookup field which is connected to listB. In listB I have for example 3 items: A, B, C. I would like to get all these items by lookup field in CSOM. Is this possible?

I have now this code:

var listA = ClientContext.Site.RootWeb.GetListByTitle(SharePointListName);

            if (list != null)
            {
                FieldLookup field = ClientContext.CastTo<FieldLookup>(listA.Fields.GetByInternalNameOrTitle(lookupFieldColumnName));

                ClientContext.Load(field);
                ClientContext.ExecuteQuery();

                // some logic to get all choices from this lookup field, I expect A, B, C from listB
            }
0

You could do it like this:

var listA = ClientContext.Site.RootWeb.GetListByTitle(SharePointListName);

var field = ClientContext.CastTo<FieldLookup>(listA.Fields.GetByInternalNameOrTitle(lookupFieldColumnName));
ClientContext.Load(field);
ClientContext.ExecuteQuery();

var lkField = field as FieldLookup;
ClientContext.Load(lkField, f => f.LookupList);
ClientContext.ExecuteQuery();

var listB = ClientContext.Site.RootWeb.Lists.GetById(new Guid(lkField.LookupList));

var itemColl = listB.GetItems(CamlQuery.CreateAllItemsQuery());
ClientContext.Load(itemColl);
ClientContext.ExecuteQuery();

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.