question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UserFields cleared after ListItem Update

See original GitHub issue

Category

  • 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

  1. Create a List with at least one User Column
  2. Populate the list
  3. Retrieve the ListItem in code (e.g. via GetByIdAsync)
  4. 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:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
stevedDevcommented, Jun 15, 2021

@jansenbe, Ah! Good point, Thanks. - You may notice that line was just copied from one of the samples verbatim 😃

1reaction
jansenbecommented, Jun 15, 2021

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Edit/Update List Item Based User That Created that Item
I am using Dialog popup to create a new list item which uses a people picker to automatically fill in the user field....
Read more >
How to clear fields in SharePoint list items using Power ...
Updating List Items. When I run this flow an item will be created and I can use the ID of this item to...
Read more >
Working with list item fields | PnP Core SDK
Working with user fields involves either directly instantiating an FieldUserValue instance or ... Clear(); // Update the item on the server await addedItem....
Read more >
Item Updating list item event receiver on Person or Group ...
1 Answer 1 ... You can test if your column have changed during the ItemUpdating event. Inside SPItemEventProperties you can find Property called ......
Read more >
Solved: Update blank/Null value to fields (Date, User, Cho...
Issue : PowerApps does not update the field to empty / null value. The field value remains as such in list. Solution :...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found