How to include Project's FieldValues in CSOM request
Asked Answered
W

1

10

I'm trying to pull all Projects information from SharePoint using Client Side Object Model (CSOM). Here is how I'm getting Projects information:

projectContext.Load(projectContext.Projects,
    c =>
        c.Where(p => p.Id == new Guid(id))
            .IncludeWithDefaultProperties(f => f.Name, f => f.Owner.Id, f => f.CreatedDate,
                f => f.StartDate, f => f.FinishDate, f => f.PercentComplete, f => f.Description));

projectContext.Load(projectContext.LookupTables, c => c.Include(f => f.Id, f => f.Entries));
projectContext.Load(projectContext.Web.SiteUsers);
projectContext.ExecuteQuery();

However, I also need to retrieve the FieldValues property from those projects, and I can't figure out how to include it in the same query. I found how to do it on the project level after I retrieved projects in from the code above, like this:

var pubProject = project.IncludeCustomFields;
projectContext.Load(pubProject);
projectContext.Load(pubProject.CustomFields);

projectContext.ExecuteQuery();

var fieldValues = pubProject.FieldValues;

Now pubProject will contain FieldValues information, but using that approach for all projects becomes too slow (it takes 1 - 4 seconds to make a call to SharePoint), since I need to make an additional request for each project and best practice for CSOM is to make as few calls as possible.

If I include FieldValues in the include fields, like this:

projectContext.Load(projectContext.Projects,
    c =>
        c.Where(p => p.Id == new Guid(id))
            .IncludeWithDefaultProperties(f => f.Name, f => f.Owner.Id, f => f.CreatedDate,
                f => f.StartDate, f => f.FinishDate, f => f.PercentComplete, f => f.Description, f => f.FieldValues));

I'm getting following error:

The query expression 'f.FieldValues' is not supported.

Wrist answered 24/4, 2015 at 14:44 Comment(0)
H
0

I think you need to put f => f.CustomFields in your .IncludeWithDefaultProperties statement instead of f.FieldValues -- Loading CustomFields should cause FieldValues to be populated

Hali answered 15/6, 2016 at 18:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.