Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to load computed fields from sharepoint list

I am new to SharePoint. I need to load some fields values from SP list using ClientContext. I use sharepoint client object model.

Here is my code:

...
//Web spWeb
//CamlQuery camlQuery                        

List spList = spWeb.Lists.GetById(parameters.Config.List.ID);

ListItemCollection  itemsCollection = spList.GetItems(camlQuery);

ClientContext.Load(itemsCollection, items => items.ListItemCollectionPosition);

ClientContext.Load(itemsCollection, items => items.Include(item => item.HasUniqueRoleAssignments, item => item.EffectiveBasePermissions, item => item.Id, item => item.FileSystemObjectType));                 

foreach (Dk14PhysicalField field in parameters.FieldsToReturn)//all required fields come here
{                   
    ClientContext.Load(itemsCollection, items => items.Include(item => item[field.PhysicalName]));
}

try
{                      
    ClientContext.ExecuteQuery();
}
catch (Exception ex)
{
    //get exception here: Field or property "LinkTitle" does not exist.
}

Where CamlQuery xml is:

<View Scope="RecursiveAll">
<ViewFields>
<FieldRef Name="LinkTitle"/>
<FieldRef Name="Summary_x0020_Business_x0020_Des"/>
<FieldRef Name="City"/>
<FieldRef Name="Title"/>
<FieldRef Name="LinkTitleNoMenu"/>
<FieldRef Name="Modified"/>
<FieldRef Name="Author"/>
</ViewFields>
<RowLimit>2147483647</RowLimit>
<Query>
<OrderBy Override="TRUE">
<FieldRef Name="ID"/>
</OrderBy>
<Where>
<Or>...some conditions here...</Or>
</Where>
</Query>
</View>

This code works fine until I try to load computed fields LinkTitle or LinkTitleNoMenu In this case I get the exception on ExecuteQuery: 'Field or property "LinkTitle" does not exist.'

Theoretically I can get these computed fields. To do that I need not to load ListItemCollectionPosition and include only computed fields to ClientContext. If I don't do one of these tricks the execution will fail with different errors.

Do you have any ideas?

like image 240
algreat Avatar asked Dec 05 '25 14:12

algreat


1 Answers

It seems that when you add the ListItemCollectionPosition field like this

ClientContext.Load(itemsCollection, items => items.ListItemCollectionPosition);

It automatically sets the value of SelectAllProperties = true in the Request and this then prevents the Computed columns from returning.

You then end up with the message 'Field or property "XYZ" does not exist.'

This only occurs on the later versions of the CSOM Client Components i.e. schema version 15.0.0.0 and Library version 16.0.0.0

After much trial and error I have found that by adding this as a second parameter on a single call this does not happen.

For example requesting ID and ListItemCollectionPosition this way does not set the SelectAllProperties = true.

ClientContext.Load(listitems, items => items.Include(item => item["ID"]), l => l.ListItemCollectionPosition);

I would suggest that it is a Bug in the Library but this seems to get around it.

like image 118
Sean Cleaver Avatar answered Dec 08 '25 17:12

Sean Cleaver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!