使用 SharePoint Web 服务/对象模型批准 SharePoint 工作流任务 [英] Approve a SharePoint workflow task using SharePoint Web Services / Object Model

查看:34
本文介绍了使用 SharePoint Web 服务/对象模型批准 SharePoint 工作流任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个工作流是 SharePoint Designer,并将其与一个列表相关联.工作流会创建一个批准流程,因此 SharePoint 在任务"列表中创建一个任务,以便用户可以批准或拒绝.

I have created a workflow is SharePoint Designer and associated it with a list. The workflow creates an approval process, so SharePoint creates a task in the Tasks list so that the user can approve or reject.

我需要做的是在不打开任务列表中的任务的情况下批准或拒绝任务.经过一番研究,我发现我可以使用 SharePoint Web Services.但是我感到很迷茫,因为我不知道哪个服务,例如Lists.asmx,以及哪种方法,例如UpdateListItems,调用.

What I need to do is to approve or reject the task without opening the task in the task list. After some research I figured that I can use SharePoint Web Services. However I feel lost as I don't know which service, e.g. Lists.asmx, and which method, e.g. UpdateListItems, to call.

有人可以指导我完成以下操作:
1- 批准 SharePoint Web Services 工作流任务是否可行?
2- 你能告诉我一个如何批准任务的例子,例如调用哪个服务和方法,参数应该是什么?

Can someone guide me through the following:
1- Is it feasible to approve a workflow task SharePoint Web Services?
2- Can you show me an example of how to approve a task, e.g. which service and method to call and what should be the parameters?

更新
我一直在使用以下 XML 来设置工作流以完成:

Update
I have been using the following XML to set the workflow to complete:

 batchElement.InnerXml = "<Method ID='1' Cmd='Update'>" // Also used Moderate
                + "<Field Name='ID'>115</Field>"
                + "<Field Name='Status'>Completed</Field>"
                + "<Field Name='FormData'>Completed</Field>" // Also used Approved
                + "<Field Name='WorkflowOutcome'>Approved</Field>"
                + "<Field Name='Completed'>True</Field>"
                + "<Field Name='PercentComplete'>1</Field>"
                + "<Field Name='_ModerationStatus'>0</Field>"
                + "</Method>";

任务列表项已更新,但 WorkflowOutcome 仍为空,工作流不会移至下一步.
我还缺少什么?

The task list item is updated but the WorkflowOutcome remains empty and the workflow doesn't move to the next step.
What else I am missing?

更新 #2
我怀疑任务列表项的 ExtendedProperties.对于使用 UI 完成的项目,ExtendedProperties 显示 ws_TaskStatus='Approved'.但是,对于使用代码 ws_TaskStatus 批准的项目不存在.

Update #2
I am suspecting the ExtendedProperties of the task list item. For an item that was completed using the UI, the ExtendedProperties shows ws_TaskStatus='Approved'. However for an item that was approved using the code ws_TaskStatus doesn't exist.

更新 #3
从 MSDN 帖子中,我被告知使用 Workflow.asmx 而不是 Lists.asmx.
我使用了以下代码:

Update #3
From an MSDN post, I was told to use the Workflow.asmx instead of the Lists.asmx.
I have used the following code:

WorkflowService.Workflow listProxy = new WorkflowService.Workflow();
listProxy.Url = "http://<server_name>/_vti_bin/workflow.asmx";
listProxy.UseDefaultCredentials = true;

int todoID = 118;
Guid tasklistID = new Guid("{79ABFDE7-0398-4AD7-918A-0D40204E7726}");
string itemURL = "http://<server_name>/TestLibrary/volshext.log";
XmlDocument taskData = new XmlDocument();
taskData.Load(@"..\..\TaskData.xml");

try
{
   XmlNode response = listProxy.AlterToDo(itemURL, todoID, tasklistID, taskData.DocumentElement);
   Console.WriteLine(response.InnerText);
}

我用来批准任务的 XML 是

The XML I am using to approve the task is

<my:myFields xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD" >
 <my:TaskStatus>#</my:TaskStatus>
 <my:Comments />
 <my:DelegateTo />
 <my:NewDescription>Please approve Workflow Demo</my:NewDescription>
 <my:NewDueDate />
 <my:RequestTo />
 <my:Decline>0</my:Decline>
 <my:dcr>0</my:dcr>
 <my:Status>Completed</my:Status>
</my:myFields>

但任务再次更新,但工作流程没有继续前进.

But again the task was updated but the workflow didn't move forward.

更新 #4
我已经对 SharePoint 服务器对象模型进行了最后一次试验,但同样,任务已更新,但工作流并未向前推进.
这是我的代码:

Update #4
I have made one last trial with SharePoint server object model however, again, the task is updated but the workflow is not moving forward.
Here is my code:

SPSite site = new SPSite("http://sitenamehere/");
using (SPWeb web = site.OpenWeb())
{
   SPList list = web.Lists["Shared Documents"];
   //SPListItem item = list.GetItemById(18);
   SPListItem item = list.GetItemByUniqueId(new Guid("5300d16e-94f8-4338-8206-4a57ab7c369b"));
   SPWorkflow workflow = item.Workflows[0];
   SPWorkflowTask task = workflow.Tasks[0];
   Hashtable ht = new Hashtable();
ht[SPBuiltInFieldId.Completed] = "TRUE"; ht["Completed"] = "TRUE"; ht[SPBuiltInFieldId.PercentComplete] = 1.0f; ht["PercentComplete"] = 1.0f; ht["Status"] = "Completed"; ht[SPBuiltInFieldId.TaskStatus] = SPResource.GetString(new CultureInfo((int)task.Web.Language, false), Strings.WorkflowStatusCompleted, new object[0]); //ht["TaskStatus"] = "#"; //ht["ows_TaskStatus"] = "Approved"; //ht["FormData"] = SPWorkflowStatus.Completed; //ht["Outcome"] = "Approved"; //task.ModerationInformation.Status = SPModerationStatusType.Approved;
web.AllowUnsafeUpdates = true; SPWorkflowTask.AlterTask((task as SPListItem), ht, true); }

推荐答案

经过大量的试验和调查,我才让以下代码工作来批准任务

After a lot of trials and investigation I just had the following code working to approve the task

SPSite site = new SPSite("http://servername/");
using (SPWeb web = site.OpenWeb())
{
    SPList list = web.Lists["TestList"];
    SPListItem item = list.GetItemById(22);
    SPWorkflow workflow = item.Workflows[0];
    SPWorkflowTask task = workflow.Tasks[0];

    Hashtable ht = new Hashtable();             
    ht[SPBuiltInFieldId.Completed] = "TRUE";
    ht["Completed"] = "TRUE";
    ht[SPBuiltInFieldId.PercentComplete] = 1.0f;
    ht["PercentComplete"] = 1.0f;
    ht["Status"] = "Completed";
    ht[SPBuiltInFieldId.TaskStatus] = SPResource.GetString(new CultureInfo((int)task.Web.Language, false), Strings.WorkflowStatusCompleted, new object[0]);
    ht[SPBuiltInFieldId.WorkflowOutcome] = "Approved";
    ht["TaskStatus"] = "Approved";
    ht["FormData"] = SPWorkflowStatus.Completed;

    web.AllowUnsafeUpdates = true;
    SPWorkflowTask.AlterTask((task as SPListItem), ht, true);
}

我怀疑 ht["TaskStatus"] = "Approved"; 是解决它的属性.无论如何,我将尝试缩小需要更改的属性集.

I suspect that ht["TaskStatus"] = "Approved"; is that attribute that solved it. Anyway I will try to narrow on the set of properties that need to be changed.

这篇关于使用 SharePoint Web 服务/对象模型批准 SharePoint 工作流任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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