6

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

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

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

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

 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 保持为空,并且工作流不会移动到下一步。
我还缺少什么?

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

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

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 是

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

但是再次更新了任务,但工作流程没有前进。

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

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

4

3 回答 3

5

经过大量试验和调查后,我刚刚使用以下代码来批准任务

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";是解决它的那个属性。无论如何,我将尝试缩小需要更改的属性集。

于 2011-02-23T10:29:04.630 回答
3

您可以使用以下代码,该代码使用列表 Web 服务和 UpdateListItems 方法。关键是使用 Cmd='Moderate'

 public static XmlNode UpdateListItemApprove()
 {
            listservice.Lists listProxy = new listservice.Lists();


            string xml = "<Batch OnError='Continue'><Method ID='1' Cmd='Moderate'><Field Name='ID'/><Field Name='FileRef'>http://basesmcdev2/sites/tester1/approvals/KL022030.lic</Field><Field Name=\"_ModerationStatus\" >0</Field></Method></Batch>";

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);

            XmlNode batchNode = doc.SelectSingleNode("//Batch");

            listProxy.Url = "http://basesmcdev2/sites/tester1/_vti_bin/lists.asmx";
            listProxy.UseDefaultCredentials = true;

            XmlNode resultNode = listProxy.UpdateListItems("approvals", batchNode);

            return resultNode;


}
于 2011-01-27T09:57:27.640 回答
3

我不确定 Madhur 的解决方案是否适用于相关项目或任务,但要更新任务,请尝试:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<UpdateListItems
xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listName>Tasks</listName>
<updates>
<Batch OnError="Continue" ListVersion="1">
<Method ID="1" Cmd="Update">
<Field Name="ID">199</Field>
<Field Name="Outcome">Approved</Field>
<Field Name="Status">Completed</Field>
<Field Name="ows_TaskStatus">Approved</Field>
</Method>
</Batch>
</updates>
</UpdateListItems>
</soap:Body>
</soap:Envelope>

服务信息:

http://objectmix.com/sharepoint/800144-updatelistitems-web-service-does-not-update-field.html

已批准字段的信息:

http://social.msdn.microsoft.com/Forums/en/sharepointworkflow/thread/6712d379-2df6-4223-9a29-b2e60493f1b6

http://social.msdn.microsoft.com/Forums/en/sharepointworkflow/thread/3dc95190-cc61-4067-ac35-2d1a82fad499

于 2011-01-27T10:07:50.273 回答