3

在下面的代码中,以下行

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

1 回答 1

5

如果该项目不处于任何工作流状态或该项目所在的工作流状态没有任何 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);
于 2013-08-09T06:48:59.947 回答