使用API​​执行Sitecore工作流状态操作

Ale*_*nko 2 api workflow sitecore sitecore6 sitecore-workflow

我想知道是否可以通过API执行Sitecore工作流操作.我不能从这里使用这个方法:http://sdn.sitecore.net/Snippets/Workflow/Change%20the%20Workflow%20State%20on%20an%20Item%20via%20API.aspx(执行将触发状态的命令更改).

我想要的是以编程方式创建一个项目,然后将工作流程状态设置为"等待批准",例如,即使没有设置"下一步"的命令.

理想情况下,它会是这样的

foreach (var action in awaitingForApprovalState.Actions)
{
  action.Execute();
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*lak 6

下面是设置项状态并执行处于此状态的操作的代码:

public void MoveToStateAndExecuteActions(Item item, ID workflowStateId)
{
    Sitecore.Workflows.IWorkflowProvider workflowProvider = Item.Database.WorkflowProvider;
    Sitecore.Workflows.IWorkflow workflow = workflowProvider.GetWorkflow(item);

    // if item is in any workflow
    if (workflow != null)
    {
        using (new Sitecore.Data.Items.EditContext(item))
        {
            // update item's state to the new one
            item[Sitecore.FieldIDs.WorkflowState] = workflowStateId.ToString();
        }

        Item stateItem = ItemManager.GetItem(workflowStateId, 
            Language.Current, Sitecore.Data.Version.Latest, item.Database, SecurityCheck.Disable);

        // if there are any actions for the new state
        if (!stateItem.HasChildren)
            return;

        WorkflowPipelineArgs workflowPipelineArgs = new WorkflowPipelineArgs(item, null, null);

        // start executing the actions
        Pipeline pipeline = Pipeline.Start(stateItem, workflowPipelineArgs);
        if (pipeline == null)
            return;
        WorkflowCounters.ActionsExecuted.IncrementBy(pipeline.Processors.Count);
    }
}
Run Code Online (Sandbox Code Playgroud)