3

Could Some one help me updating the workflow and workflow state field for all the sub items under the item say sitecore/content/ParentItem .

I have created a new workflow and set it up in standard values,But For the existing items i want to change the workflow to new Workflow and state to new Workflow State .

3 Answers 3

3

To update the workflow for the current item’s descendants, you can use the below script

$contentsToUpdate = Get-Item master: -Query "sitecore/content/ParentItem//*" -Language "en-GB"

foreach($content in $contentsToUpdate) {        

    $content.Editing.BeginEdit()
    $content.Fields["__Default workflow"].Value = "Item ID of Default Workflow"
    $content.Fields["__Workflow state"].Value = "Item ID of Workflow state"
    $content.Fields["__Workflow"].Value = "Item ID of Workflow"
    $content.Editing.EndEdit()

}

Note the -Language is equals to en-GB. Change it according to the language you want to update.

1

Following blog post contains script https://mtgeekblog.wordpress.com/2016/11/30/first-blog-post/


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.
## Uncomment below two lines if you are ready to go for updating
#get-item . -Language * | foreach-object { SetWorkFlow($_) }
#get-childitem . -recurse -Language * | foreach-object { SetWorkFlow($_) }
0

Do reset for existing items

Set-Location -Path "master:/sitecore/content/ParentItem"

function Reset-Workflows {

    foreach ($item in Get-ChildItem . -Recurse)
    {
        foreach ($versionItem in $item.Versions.GetVersions($true))
        {
            Write-Host "trying update an item " $versionItem.ID
            if ($versionItem.Fields["__Default workflow"].Value -eq "[old_workflow_id]")
            {
                $versionItem | Reset-ItemField -Name "__Workflow state" -IncludeStandardFields
                $versionItem | Reset-ItemField -Name "__Default workflow" -IncludeStandardFields
                $versionItem | Reset-ItemField -Name "__Workflow" -IncludeStandardFields

                Write-Host "Item updated: " $versionItem.ID " - " $versionItem.Language;
            }
        }   
    }

}

Reset-Workflows

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.