C# 以编程方式向SharePoint呼叫中心应用程序添加服务调用

C# 以编程方式向SharePoint呼叫中心应用程序添加服务调用,c#,sharepoint,C#,Sharepoint,我正在使用sharepoint,并尝试将服务呼叫添加到microsoft的呼叫中心应用程序模板中。我可以添加一个名称,代码如下: SPSite allSites = new SPSite(siteURL); SPWeb site = allSites.AllWebs[siteName]; SPListItemCollection requestsList = site.Lists[serviceRequests].Items; SPListItemCollection customerList

我正在使用sharepoint,并尝试将服务呼叫添加到microsoft的呼叫中心应用程序模板中。我可以添加一个名称,代码如下:

SPSite allSites = new SPSite(siteURL);
SPWeb site = allSites.AllWebs[siteName];
SPListItemCollection requestsList = site.Lists[serviceRequests].Items;
SPListItemCollection customerList = site.Lists[customers].Items;

SPListItem item = requestsList.Add();
item["Service Request"] = "Program Test";
//item["Customer"] = "Donald Duck";
item["Customer"] = customerList[0];
item.Update();
首先,我试着只使用客户名称,但这不起作用。然后,我获取了客户列表并尝试使用客户列表项,但仍然出现相同的错误:

“更新列表项时使用了无效数据。您试图更新的字段可能是只读的。”

是否有人具有从类似代码向sharepoint添加信息的经验?是否有办法确定哪些字段是只读的(如果有的话)


谢谢

当您有一个查找字段而没有为其指定值时,有时会发生这种情况。例如,当您有一个包含以下项目的列表时

  • 顾客:文本
  • 部门:查找部门列表和必填项

    SPListItem item = requestsList.Add();        
    item["Customer"] = "as";
    item.Update();
    

  • 现在您将看到此错误。因为您没有指定Department字段的值,所以我找到了此问题的解决方案。

    您不需要走那么远就可以完成该工作。将索引值设置为查找字段而不是1#值格式就足够了。