UserFields cleared after ListItem Update
See original GitHub issueCategory
- Bug
Describe the bug
When issuing an Update/UpdateAsync against a List item, if there are any User Fields included in the List, unless they are updated by setting the Principal property, they are being cleared (nulled out) in the list.
Looks to be something wrong with the “Change tracking” for User fields, i.e. it thinks they have changed even when they haven’t.
Steps to reproduce
- Create a List with at least one User Column
- Populate the list
- Retrieve the ListItem in code (e.g. via GetByIdAsync)
- Issue an Update against the ListItem using UpdateAsync
The User column has been cleared/null’d.
If any other updates are applied in the code, e.g. update a Title column, those values do come thru. The only way I could get the User field to remain was to set the User column value in code against the Principal property (also didn’t work if I just set the LookupId property for it) with the existing value.
Expected behavior
No change to the User column if no changes applied to it in the code.
Environment details (development & target environment)
Testing performed using an Azure Function (Asp.Net Core 3.1)
Startup uses: `
builder.Services.AddPnPCore( options =>
{
// Disable telemetry because of mixed versions on AppInsights dependencies
options.DisableTelemetry = true;
// Configure an authentication provider with certificate (Required for app only)
var authProvider = new X509CertificateAuthenticationProvider( azureFunctionSettings.ClientId,
azureFunctionSettings.TenantId,
StoreName.My,
StoreLocation.CurrentUser,
azureFunctionSettings.CertificateThumbprint );
// And set it as default
options.DefaultAuthenticationProvider = authProvider;
// Add a default configuration with the site configured in app settings
options.Sites.Add( "Default",
new PnP.Core.Services.Builder.Configuration.PnPCoreSiteOptions
{
SiteUrl = azureFunctionSettings.SiteUrl,
AuthenticationProvider = authProvider
} );
} );
Testing code (in the Function):
using (var pnpContext = await pnpContextFactory.CreateAsync( "Default" ))
{
var requestsList = await pnpContext.Web.Lists.GetByIdAsync( requestOptions.ListIdRequests, p => p.Title, p => p.Items,
p => p.Fields.QueryProperties( p => p.InternalName, p => p.FieldTypeKind, p => p.TypeAsString, p => p.Title ) );
var requestItem = await requestsList.Items.GetByIdAsync( requestId );
await requestItem.UpdateAsync();
}
`
- SDK version: 1.2
- OS: Windows 10
- SDK used in: Azure Function
- Framework: .NET Core v3.1
- Tooling: Visual Studio 2019
- Additional details: No specific PnP configuration
Additional context
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
@jansenbe, Ah! Good point, Thanks. - You may notice that line was just copied from one of the samples verbatim 😃
@stevedDev : On a side note: your sample loads all the list items in
...GetByIdAsync( requestOptions.ListIdRequests, p => p.Title, p => p.Items...
while later on you load the needed list item again. In this case the code will be faster if omit the first load of the Items collection.