sitecore
Flusso di lavoro
Ricerca…
Imposta le azioni Stato ed Esegui in quello stato
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);
}
}
Grazie a questo thread
Esecuzione del comando del flusso di lavoro per modificare lo stato del flusso di lavoro
Grazie a questo fantastico post
Se vogliamo simulare il comportamento dell'interfaccia utente di Sitecore ed eseguire il comando che cambierà lo stato del flusso di lavoro, dobbiamo utilizzare WorkflowProvider per ottenere un'istanza del flusso di lavoro assegnato all'elemento specificato e chiamare il metodo Execute con un ID comando scelto. Questo genererà tutte le azioni definite sotto il nodo dell'elemento comando, cambierà lo stato dell'elemento e genererà tutte le azioni automatiche definite sotto il nuovo nodo dello stato:
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
Autorizzato sotto CC BY-SA 3.0
Non affiliato con Stack Overflow