Skip to content

Added EnsureAndSetUserFields method to ClientContextExtensions#1195

Closed
jeppesc11 wants to merge 5 commits into
pnp:devfrom
jeppesc11:dev
Closed

Added EnsureAndSetUserFields method to ClientContextExtensions#1195
jeppesc11 wants to merge 5 commits into
pnp:devfrom
jeppesc11:dev

Conversation

@jeppesc11

Copy link
Copy Markdown

Summary

Adds a new extension method EnsureAndSetUserFields to ClientContext that provides safe assignment of user email addresses to SharePoint list item user fields with automatic user resolution and error handling.

Changes

  • Added: EnsureAndSetUserFields extension method to ClientContextExtensions.cs
  • Features:
    • Automatic user resolution using ExceptionHandlingScope for robust error handling
    • Supports batch operations for multiple field-email assignments
    • Configurable null/whitespace handling behavior
    • Follows CSOM queuing pattern (requires caller to execute operations)
      ctx.EnsureAndSetUserFields(listItem, fieldAssignments, true);
      ctx.ExecuteQueryRetry();

Usage

var fieldAssignments = new[] { ("AssignedTo", "user1@contoso.com"), ("Author", "user2@contoso.com") };
ctx.EnsureAndSetUserFields(listItem, fieldAssignments, clearIfNullOrWhiteSpace: true);
ctx.ExecuteQueryRetry();

Breaking Changes

None - this is a new addition that doesn't affect existing functionality.

@jeppesc11 jeppesc11 closed this Nov 23, 2025
@jeppesc11

Copy link
Copy Markdown
Author

I have committed too many files that are not relevant to this PR

@jeppesc11

Copy link
Copy Markdown
Author

Created new PR with the correct files #1201

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant