在下面的代码中,下面一行
WorkflowResult result = wf.Execute(SitecoreItems.MediaWorkflowApproveCommand, item, "", false);
正在抛出 Could not find command definition
错误。 ID 和所有其他属性均有效,但命令定义无效。
关于可能导致它的原因有什么想法吗?
using (new SecurityDisabler())
{
// Find all related items
ItemLink[] itemLinks = dataItem.Links.GetValidLinks();
foreach (ItemLink link in itemLinks)
{
Item item = link.GetTargetItem();
// publishing related media items - the ones that were referenced by the workflow item
// this can be extended - you can publish related aliases also
if (item != null && item.Paths.IsMediaItem)
{
//push field to the next state
IWorkflow wf = item.Database.WorkflowProvider.GetWorkflow(item);
WorkflowResult result = wf.Execute(SitecoreItems.MediaWorkflowApproveCommand, item, "", false);
}
}
}
最佳答案
如果该项目不处于任何工作流状态或该项目所在的工作流状态没有任何 ID 等于作为参数传递的命令 ID 的子级,则会抛出此异常。
尝试执行以下代码:
if (item.Database.Name == "web")
{
throw new Exception("Can not execute workflow command in web database");
}
if (String.IsNullOrEmpty(item[FieldIDs.WorkflowState]))
{
throw new Exception("Workflow state is not set for the item");
}
Item stateItem = ItemManager.GetItem(wf.GetState(item), Language.Current, Version.Latest, item.Database, SecurityCheck.Disable);
if (stateItem == null)
{
throw new Exception("Workflow state " + item[FieldIDs.WorkflowState] + " is not a part of " + wf.WorkflowID + " workflow");
}
if (stateItem.Axes.GetChild(ID.Parse(SitecoreItems.MediaWorkflowApproveCommand)) == null)
{
throw new Exception("Workflow state " + stateItem.ID + " does not have a child command with id " + SitecoreItems.MediaWorkflowApproveCommand);
}
执行行之前
WorkflowResult result = wf.Execute(SitecoreItems.MediaWorkflowApproveCommand, item, "", false);
关于c# - Sitecore Workflow 命令抛出 "Could not find command definition"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18135757/