Approve a SharePoint workflow task using SharePoint Web Services / Object Model

前端 未结 3 939
清酒与你
清酒与你 2020-12-30 13:53

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 t

3条回答
  •  天涯浪人
    2020-12-30 14:50

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

    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.

提交回复
热议问题