简体   繁体   English

Sharepoint 基础 REST 接口,更新 object 失败

[英]Sharepoint Foundation REST interface, updating an object fails

I'm using the REST interface detailed here - https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ff521587(v%3Doffice.14)我正在使用此处详细介绍的 REST 接口 - https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ff521587(v%3Doffice.14)

As a proof of concept, I'm trying to access an item in a list from our Sharepoint 2010 intranet site and update a field.作为概念证明,我正在尝试从我们的 Sharepoint 2010 内部网站点访问列表中的项目并更新字段。

To do this, I created a Connected OData service to the endpoint (AccountingWorkflowsDataContext) and here is my code -为此,我创建了一个连接到端点 (AccountingWorkflowsDataContext) 的 OData 服务,这是我的代码 -

var tasks = new AccountingWorkflowsDataContext(new Uri(
                    "https://mysite/_vti_bin/ListData.svc"));


tasks.Credentials = new NetworkCredential("username", "password", "domain");
var task = tasks.GLRecsTasks.Where(x => x.StatusValue != "Completed" && (x.AssignedToId == 1 || x.AssignedToId == 2)).First();

task.DueDate = DateTime.Now.AddDays(5);
tasks.UpdateObject(task);
tasks.SaveChanges();

I can connect to the list and I'm picking up the correct item and I'm tracking changes to it as well, however, the call to SaveChanges always fails with the message "An error occurred while processing this request."我可以连接到列表,我正在选择正确的项目,并且我也在跟踪对它的更改,但是,对 SaveChanges 的调用总是失败,并显示消息“处理此请求时发生错误”。 and the innner exception is -内在的例外是 -

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <code></code>
  <message xml:lang="en-US">An error occurred while processing this request.</message>
</error>

Can someone shed some light on this.有人可以对此有所了解。

I had to use the Managed Client Object Model to accomplish this.我必须使用托管客户端 Object Model来完成此操作。

I was attempting to retrieve an open Workflow Task assigned to a specific user and assign it to a different person and for some reason, the REST interface was throwing an error during the reassignment.我试图检索分配给特定用户的打开的工作流任务并将其分配给不同的人,由于某种原因,REST 界面在重新分配期间抛出错误。

Here is my code utilizing the Managed Client Object Model ( NOT Production-ready but something to start out with )这是我使用托管客户端 Object Model 的代码(不是生产就绪,但可以开始使用

                using (ClientContext context = new ClientContext("siteURL"))
                {
                    context.FormsAuthenticationLoginInfo = new FormsAuthenticationLoginInfo("login", "password");

                    Web web = context.Web;
                    var result = context.Web.Lists.GetByTitle("TaskListName");

                    var query = new CamlQuery()
                    {
                        ViewXml =
                            "<View><Query><Where><And><Eq><FieldRef Name='Status' /><Value Type='Text'>Not Started</Value></Eq><Eq><FieldRef Name='AssignedTo' /><Value Type='User'>UserName</Value></Eq></And></Where></Query></View>"
                    };
                    var items = result.GetItems(query);
                    context.Load(items);
                    context.ExecuteQuery();

                    foreach (var item in items)
                    {
                        item["AssignedTo"] = new FieldUserValue() { LookupId = NewUserID };
                        item.Update();
                    }

                    context.ExecuteQuery();
                }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM