Update task item programatically in Sharepoint with CSOM

て烟熏妆下的殇ゞ 提交于 2019-12-12 02:49:49

问题


I want to update a task item programatically in CSOM. Item is updating but workflow is not triggering. I need just to open the item in sharepoint and save it. Then workflow is triggering.

                    List requestTasksList = MyWeb.Lists.GetByTitle("TestRequest Tasks");

                    List<TestRequestModel> testRequestList = new List<TestRequestModel>();

                    ListItemCollection ColListItems = requestTasksList.GetItems(Spqur);

                    ctx.Load(ColListItems);
                    ctx.ExecuteQuery();

                    foreach (ListItem task in ColListItems)
                    {
                        task["Status"] = "Completed";
                        task["TaskOutcome"] = "Approved";
                        task["PercentComplete"] = 1.0;
                        task["Checkmark"] = 1;
                        task.Update();
                        requestTasksList.Update();
                    }
                    ctx.ExecuteQuery();

This is the updated task item

As i said, When i click to save button, workflow is triggering and new task is creating.


回答1:


I'm not sure if its typo but it should be

List requestTasksList = MyWeb.Lists.GetByTitle("TestRequest Tasks");

List<TestRequestModel> testRequestList = new List<TestRequestModel>();

ListItemCollection ColListItems = requestTasksList.GetItems(Spqur);

foreach (ListItem task in ColListItems)
{
  task["Status"] = "Completed";
  task["TaskOutcome"] = "Approved";
  task["PercentComplete"] = 1.0;
  task["Checkmark"] = 1;
  task.Update();
}
ctx.ExecuteQuery();



回答2:


We needed to do the same thing and have found that there are no event handlers on the workflow tasks list in SharePoint 2013. I know that there is a SPWorkflowAutostartEventReceiver on lists that have workflows auto start on add or update, so I assumed this same approach would be done for workflow tasks as well, but it is not. Since there are no event handlers on the workflow tasks list, I surmise that all workflow triggers are initiated from the server-side UI code on the task list (horrible design).

For us we need to work completely client side with no farm solution or sandboxed code. So our only solution has been to screen scrape URLs and then open pages or dialogs for the user to do things like cancel all tasks for an approval workflow. Granted, this approach still does requires user input. I suppose you could screen scrape the whole page and play back the action of hitting buttons on a task page or cancel task page if you needed to avoid user input. That would be a pain, though.



来源:https://stackoverflow.com/questions/25744010/update-task-item-programatically-in-sharepoint-with-csom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!