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","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,但是没有运气。

预先感谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)