pnp / pnpcore

The PnP Core SDK is a modern .NET SDK designed to work for Microsoft 365. It provides a unified object model for working with SharePoint Online and Teams which is agnostic to the underlying API's being called
https://aka.ms/pnp/coresdk/docs
MIT License
288 stars 188 forks source link

Pnp.Core UserMulti Field not found #1476

Closed sgalntt closed 1 month ago

sgalntt commented 1 month ago

Category

Describe the bug

I defined a list with a UserMulti Field. I populate with success a new list Item with a code C#. When I tried to read this field the code doesn't work, in the value array the field is not ready..

When the field is added to a List by Share Point Web Site, in the listitem value array the field is not ready. When the field is added to a List by Code C#, in the listitem value array the field is ready.

CODE : IList myList = context.Web.Lists.Where(x => x.Title == "ListName").ToList().FirstOrDefault(); var items = myList.Items.ToList(); IListItem itm = items.FirstOrDefault(); itm.Load(x => x.All);

//work var infoMultiUserCode = (itm["UserMultiDefinedPnp"] as IFieldValueCollection)?.Values.OfType().ToArray(); var infoMultiUser = (itm["UserMultiDefinedonSPOWeb"] as IFieldValueCollection)?.Values.OfType().ToArray();

Steps to reproduce

Define a List on share point online named ListName. Add a field UserMulti on a List with Share Point Interface named UserMultiDefinedonSPOWeb. Add a field UserMulti on a List with Pnp Core named UserMultiDefinedPnp. Add an Item to the list.

Execute the code infoMultiUserCode has value infoMultiUser has null value

Environment details (development & target environment)

C# .NET 8.0 Pnp.Core 1.12.0 OS : Windows 10

Field Added by code myList.Fields.AddUserMulti("MultiUser", new FieldUserOptions() { Group = "TEST GROUP", Required = true, AllowDisplay = true, Presence = true, SelectionMode = FieldUserSelectionMode.PeopleAndGroups // TODO Must be tested when support for SharePoint groups is implemented //SelectionGroup = 1 });

Thanks for your contribution! Sharing is caring.

jansenbe commented 1 month ago

@sgalntt : can you cross that the used field name "UserMultiDefinedonSPOWeb" is the correct static name of the field in the list? When creating fields using the UX SharePoint can alter the internal/static name and you need to ensure you pick the right one.

To check the field, navigate to the list settings page and click on the field you're testing. This opens the FldEdit.aspx page, when you inspect the URL you'll see something like https://bertonline.sharepoint.com/sites/prov-1/_layouts/15/FldEdit.aspx?List=%7B7D644D41%2DD86E%2D4594%2D99DE%2D479594A68FD9%7D&Field=I%5Fx0020%5Fhave%5Fx0020%5Fa%5Fx0020%5Fspace

If you URL decode (https://www.urldecoder.io/) the Field url variable you'll see the static name you need to use when working with the field via code:

image

sgalntt commented 1 month ago

Ok, solved!

I create a wrong type field by the interface.

The flag Allow multiple selections is disabled when I created the item. When the code try to cast the field, it doesn't work. Return null value