TransWikia.com

How can't i refresh ListItemAllFields when site column is updated?

SharePoint Asked by Agustín on December 17, 2021

I’m updating site column with this code:

Field field = site.Fields.GetById(property.MappedSiteColumn);
clientContext.Load(field);

field.SchemaXml = xml;
clientContext.ExecuteQuery();

The site column in SharePoint change correctly.

enter image description here

But, when i search the files that content this site column with this code:

File file = site.GetFileByServerRelativeUrl(documentUrl);
ListItem item = file.ListItemAllFields;

clientContext.Load(file);
clientContext.Load(item);
clientContext.ExecuteQuery();
var fieldValues = item.FieldValues

The change in the Site Column is not refreshed in fieldValues variable.
How can’t i make this refresh?

One Answer

When you are setting the SchemaXml of the field, you are setting it in the field that is in the Fields collection at the site level.

When fields are used in lists and libraries, a copy of the field is made and added to the Fields collection at the list level. In order for changes to the field at the site level to be pushed down to the field copies at the list level, you have to explicitly tell SharePoint to do that.

In the server side object model, what you would do would be to call SPField.Update(true).

Disclaimer - I have very little experience with the CSOM, however, it is my very strong suspicion that what you are going to need to do is call Field.UpdateAndPushChanges(true).

So your code would look something like

Field field = site.Fields.GetById(property.MappedSiteColumn);
clientContext.Load(field);

field.SchemaXml = xml;
field.UpdateAndPushChanges(true);
clientContext.ExecuteQuery();

Answered by Dylan Cristy on December 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP