Sitecore工作流命令抛出“;找不到命令定义“”;错误

本文关键字:命令 定义 错误 找不到 工作流 Sitecore | 更新日期: 2023-09-27 18:26:52

在下面的代码中

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);
                    }
                }
            }

Sitecore工作流命令抛出“;找不到命令定义“”;错误

如果该项不处于任何工作流状态,或者该项所处的工作流状态没有任何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);