简体   繁体   中英

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)

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.

To do this, I created a Connected OData service to the endpoint (AccountingWorkflowsDataContext) and here is my code -

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." 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.

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.

Here is my code utilizing the Managed Client Object Model ( NOT Production-ready but something to start out with )

                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();
                }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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