csom - SharePoint 2019 CSOM 不保存 FieldUserValue
问题描述
当我在 SharePoint2019 列表中插入或更新包含用户列的项目时,我遇到了一个奇怪的问题,保存完成且没有错误,但用户列始终具有空值,
下面是我的代码
context.Load(context.Web, web => web.Lists);
await context.ExecuteQueryAsync();
List RiskList = context.Web.Lists.GetByTitle("Risks");
context.Load(RiskList);
context.Load(RiskList, r => r.Fields);
await context.ExecuteQueryAsync();
ListItem listItem = RiskList.GetItemById(projectRisks.Id);
List<ListItemFormUpdateValue> listItemFormUpdateValue = new List<ListItemFormUpdateValue>();
if (projectRisks.AssignedTo.HasValue)
{
listItem["AssignedTo"] = new FieldUserValue() { LookupId = projectRisks.AssignedTo.Value };
}
if (projectRisks.Owner.HasValue)
{
User OwnerUser = context.Web.SiteUsers.GetById(projectRisks.Owner.Value);
context.Load(OwnerUser);
await context.ExecuteQueryAsync();
listItem["Owner"] = new FieldUserValue() { LookupId = OwnerUser.Id };
}
listItemFormUpdateValue.Add(new ListItemFormUpdateValue() { FieldName = "Category", FieldValue = GetSPSelectedChoiceValue(context, RiskList, "Category", projectRisks.CategoryName).Result });
listItemFormUpdateValue.Add(new ListItemFormUpdateValue() { FieldName = "Status", FieldValue = GetSPSelectedChoiceValue(context, RiskList, "Status", projectRisks.StatusName).Result });
listItem["Contingency_x0020_plan"] = projectRisks.ContingencyPlan;
listItem["Cost"] = projectRisks.Cost;
listItem["Cost_x0020_Exposure"] = string.Empty;
listItem["Description"] = projectRisks.Description;
listItem["DueDate"] = projectRisks.DueDate;
listItem["Exposure"] = projectRisks.Exposure;
listItem["Impact"] = projectRisks.Impact;
listItem["Mitigation_x0020_plan"] = projectRisks.MitigationPlan;
listItem["Probability"] = projectRisks.Probability;
listItem["Title"] = projectRisks.Name;
listItem.ValidateUpdateListItem(listItemFormUpdateValue, false, string.Empty);
listItem.Update();
await context.ExecuteQueryAsync();
正如您在 AssignTo 和 Owner Columns 中看到的那样,无论我如何尝试保存用户值,该列表都将采用默认值为 null。
I have made sure that there is values in the assigned to and Owner properties
我试过使用 ListItemFormUpdateValue 但没有运气。
提前致谢
解决方案
推荐阅读
- http - 如何让 2 个 pod 在 kubernetes 中相互通信?
- android - 删除数据时如何更改setText
- python - 如何创建 .mdb 文件?
- google-cloud-platform - Data Studio Report的数字缩写如何设置图表设置?
- maven - 在 Jenkins 中跳过 Maven 的 ssl 证书检查
- amazon-web-services - 如何通过 SNS 和 Cloudwatch 发送短信?
- javascript - 如何在我的所有网页中显示用户名...?
- ios - 使用文本字段作为搜索文本的输入实现自定义搜索栏以及如何在 ios swift 中调用搜索 api
- powershell - 在 CSV 中添加额外的标题
- r - 查找入住率