c# - 以编程方式批准/拒绝工作流程并添加评论

标签 c# sharepoint sharepoint-2010 sharepoint-workflow sharepoint-api

我正在尝试以编程方式批准/拒绝 SharePoint 中的工作流。我可以成功做到这一点,但我无法添加评论。我从一年 old question 得到了我的代码,也没有得到回答,所以我想我会开始一个新问题。

我的代码:

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]);
if (param == "Approved")
{
    ht[SPBuiltInFieldId.WorkflowOutcome] = "Approved";
    ht["TaskStatus"] = "Approved";
    if (!string.IsNullOrEmpty(comments))
    {
        ht[SPBuiltInFieldId.Comments] = comments;
        ht["Comments"] = comments;
        ht[SPBuiltInFieldId.Comment] = comments;
    }
}
else
{

    ht[SPBuiltInFieldId.WorkflowOutcome] = "Rejected";
    ht["TaskStatus"] = "Rejected";
    if (!string.IsNullOrEmpty(comments))
    {
        ht[SPBuiltInFieldId.Comments] = comments;
        ht["Comments"] = comments;
        ht[SPBuiltInFieldId.Comment] = comments;
    }
}
ht["FormData"] = SPWorkflowStatus.Completed;
bool isApproveReject = AlterTask(task, ht, true, 5, 100);

private static bool AlterTask(SPListItem task, Hashtable htData, bool fSynchronous, int attempts, int millisecondsTimeout)
{
    if ((int)task[SPBuiltInFieldId.WorkflowVersion] != 1)
    {
        SPList parentList = task.ParentList.ParentWeb.Lists[new Guid(task[SPBuiltInFieldId.WorkflowListId].ToString())];
        SPListItem parentItem = parentList.Items.GetItemById((int)task[SPBuiltInFieldId.WorkflowItemId]);
        for (int i = 0; i < attempts; i++)
        {
            SPWorkflow workflow = parentItem.Workflows[new Guid(task[SPBuiltInFieldId.WorkflowInstanceID].ToString())];
            if (!workflow.IsLocked)
            {
                task[SPBuiltInFieldId.WorkflowVersion] = 1;
                task.SystemUpdate();
                break;
            }
            if (i != attempts - 1)
                Thread.Sleep(millisecondsTimeout);
        }
    }
    return SPWorkflowTask.AlterTask(task, htData, fSynchronous);
}

最佳答案

要在批准/拒绝任务时向任务添加评论,您只需要使用 AlterTask 之前的行:

ht["ows_FieldName_Comments"] = comments;

任务被批准后,您可以在工作流历史列表中看到评论。

您还可以通过以下方式从任务中获取所有综合评论:

Hashtable extProperties = SPWorkflowTask.GetExtendedPropertiesAsHashtable(currentTask);

string consolidatedComments = extProperties["FieldName_ConsolidatedComments"].ToString();

关于c# - 以编程方式批准/拒绝工作流程并添加评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11550208/

相关文章:

共享点站点的 Internet Explorer 中的 Javascript 错误

c# - DivideByZeroException 编译器检查复杂度 : easier or harder in MSIL vs C# or no difference?

c# - VSPerf 和 A​​zure 云服务

sharepoint - 无需身份验证即可访问 Sharepoint Web 服务

c# - System.IO.FileNotFoundException : The Web application at http://SharePoint/could not be found. 验证您是否正确键入了 URL

sharepoint - 将文件上传到 Sharepoint 列表项

c# - 为泛型类中的静态方法设置无类型

c# - 如何以编程方式 Kindlize .HTML 或 .DOCX 或 .PDF 文件(使其适合 Kindle)?

.net - Visual Studio 2015 Professional 引发以下错误 :- Could not load file or assembly 'Microsoft. Activities.Design.Services

powershell - 共享点错误:Enable-SPFeature:此页面的安全验证无效