使用 CSOM 在 Sharepoint 中以编程方式更新任务项 [英] Update task item programatically in Sharepoint with CSOM

查看:47
本文介绍了使用 CSOM 在 Sharepoint 中以编程方式更新任务项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 CSOM 中以编程方式更新任务项.项目正在更新,但工作流程未触发.我只需要在 sharepoint 中打开该项目并保存它.然后工作流正在触发.

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

这是更新的任务项

正如我所说,当我点击保存按钮时,工作流正在触发,新任务正在创建.

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

推荐答案

我们需要做同样的事情,发现 SharePoint 2013 中的工作流任务列表上没有事件处理程序.我知道有一个 SPWorkflowAutostartEventReceiver具有工作流在添加或更新时自动启动的列表,所以我认为同样的方法也适用于工作流任务,但事实并非如此.由于工作流任务列表上没有事件处理程序,我推测所有工作流触发器都是从任务列表上的服务器端 UI 代码启动的(可怕的设计).

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

对我们来说,我们需要在没有农场解决方案或沙盒代码的情况下完全在客户端工作.因此,我们唯一的解决方案是屏幕抓取 URL,然后为用户打开页面或对话框以执行诸如取消审批工作流的所有任务等操作.当然,这种方法仍然需要用户输入.如果您需要避免用户输入,我想您可以屏幕抓取整个页面并回放点击任务页面上的按钮或取消任务页面的操作.不过那会很痛苦.

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.

这篇关于使用 CSOM 在 Sharepoint 中以编程方式更新任务项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆