sitecore
workflow
Zoeken…
Stel itemstatus in en voert acties in die status uit
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);
}
}
Dankzij deze draad
Werkstroomopdracht uitvoeren om de werkstroomstatus te wijzigen
Met dank aan deze geweldige post
Als we het Sitecore UI-gedrag willen nabootsen en de opdracht willen uitvoeren die de workflow-status zal veranderen, moeten we WorkflowProvider gebruiken om een exemplaar van de workflow te krijgen die aan het gegeven item is toegewezen en de Execute-methode oproepen met een gekozen opdracht-ID. Hiermee worden alle acties geactiveerd die zijn gedefinieerd onder het opdrachtitemknooppunt, wordt de status van het item gewijzigd en worden alle automatische acties geactiveerd die zijn gedefinieerd onder het nieuwe statusitemknooppunt:
public static WorkflowResult ExecuteCommand(Item item, string commandName, string comment)
{
IWorkflow workflow = item.Database.WorkflowProvider.GetWorkflow(item);
if (workflow == null)
{
return new WorkflowResult(false, "No workflow assigned to item");
}
WorkflowCommand command = workflow.GetCommands(item[FieldIDs.WorkflowState])
.FirstOrDefault(c => c.DisplayName == commandName);
if (command == null)
{
return new WorkflowResult(false, "Workflow command not found");
}
return workflow.Execute(command.CommandID, item, comment, false, new object[0]);
}
Modified text is an extract of the original Stack Overflow Documentation
Licentie onder CC BY-SA 3.0
Niet aangesloten bij Stack Overflow