Sitecore Workflow Is Not Working

2019-02-15 21:33发布

问题:

I already have an content item (item) with template A. Template A has not set any workflow initially and I set a new workflow in template's standard value.

If I go to the content item's workflow section, there is only "Default workflow" update. The fields "Workflow" and "State" are empty even I set "Initial State" in the workflow's property, as shown below screenshot. So, workflow process is not working on that item.

However, if I create new item with the template already set workflow, I could see all filled workflow fields based on its initial workflow setting. So, workflow process is perfectly working.

I have a number of pages without workflow setting and I'm about to assign new workflow in its templates.

How can I solve this issue???????


回答1:

I used Powershell Script and it looks like this. It updates the empty field and perfectly works.

##################################################################
##  1. Set default workflow state in template's standard value  ##
##  2. Before running script, must set correct Context Item     ##
##################################################################

function SetWorkflow($item)
{
    ## Update only items assigned __Default workflow
    if ($item."__Default workflow" -eq "{A5BC37E7-ED96-4C1E-8590-A26E64DB55EA}") {
        $item.__Workflow = "{A5BC37E7-ED96-4C1E-8590-A26E64DB55EA}";
        $item."__Workflow state" = "{190B1C84-F1BE-47ED-AA41-F42193D9C8FC}";
    }
}

## Update correct workflow information.
get-item . -Language * | foreach-object { SetWorkFlow($_) }
get-childitem . -recurse -Language * | foreach-object { SetWorkFlow($_) }

## Show Updated Result
get-item . -Language * | Format-Table Id, Name, Language, __Workflow, "__Workflow state", "__Default workflow"
get-childitem . -recurse -Language * | Format-Table Id, Name, Language, __Workflow, "__Workflow state", "__Default workflow"


回答2:

When you set the default workflow value on a standard values item it does not automatically and go through and add existing item versions into a specific workflow state. This is because any content that was previously published would become unpublished as it would go to the default state of the workflow, which is typically a draft state.

The next time you add a version to the item that now has workflow (either explicitly or by "editing" as a lower level user), its state should be set to draft as you'd expect.

If you need to migrate existing versions of items into workflow at particular state you will probably need to do this via code.