Sitecore - 更新工作流历史记录

时间:2013-04-09 04:44:46

标签: c# sitecore sitecore6

是否可以以编程方式设置工作流注释? 例如管理员用户“拒绝”工作箱中的项目,我们要求发表评论。稍后,我们的代理程序会重新审核此评论并发送电子邮件。现在我需要我的自定义模块执行相同的操作(管理员拒绝功能)。

与Sitecore使用相同的代码来设置工作流注释我猜...

1 个答案:

答案 0 :(得分:3)

以下是执行任何工作流命令的代码,假设您知道命令项的ID:

public bool Execute(Item item, ID commandId, string comment)
{
    var workflowId = item[FieldIDs.Workflow];

    if (String.IsNullOrEmpty(workflowId))
    {
        throw new WorkflowException("Item is not in a workflow");
    }

    IWorkflow workflow = item.Database.WorkflowProvider.GetWorkflow(workflowId);

    var workflowResult = workflow.Execute(commandId.ToString(), item, comment, false, new object[0]);
    if (!workflowResult.Succeeded)
    {
        var message = workflowResult.Message;
        if (String.IsNullOrEmpty(message))
        {
            message = "IWorkflow.Execute() failed for unknown reason.";
        }
        throw new Exception(message);
    }
    return true;
}