Console icon indicating copy to clipboard operation
Console copied to clipboard

Using EventDisabler for creating new language version does not set the workflow state

Open annaf-dev opened this issue 5 years ago • 2 comments

Expected Behavior

To create a new language version for a bunch of items (thousands and more) I want to use an EventDisabler. I expected the language versions to be created as they would if I would do it directly in Sitecore.

Actual Behavior

Unfortunately, using the EventDisabler creates the expected language version, but the new version has an empty workflow state field. So the new language version has a workflow but no workflow state.

For comparison I created a similar event in Sitecore directly which is triggered at the "item:versionAdding" event. In the called method I use a using (new EventDisabler()) in which I create a new language version for a predefined list of items. That worked perfectly and also sets the initial workflow state.

Steps to Reproduce the Problem

Make sure you have defined a workflow at the Standard Values of your item template. Get a list of items, define a new UsingBlock (with the EventDisabler) and add a new language version for each item. Example:

$targetLanguage = [get-your-target-language-here]
$items = [get-your-items-here]
New-UsingBlock (New-Object Sitecore.Data.Events.EventDisabler) {
  $items | ForEach-Object {
    Add-ItemLanguage -Item $_ -TargetLanguage $targetLanguage -IfExist Skip -DoNotCopyFields
  }
}

After that have a look at the newly created language version and check the Workflow State field.

I use Sitecore 9.0.1 and SPE 5.0.

  • [ ] Tested issue with clean install of Sitecore and the latest available version of SPE.

  • [x] Asked questions on the Sitecore Slack Chat channel.

  • [x] Reviewed questions and answers on the Sitecore Stack Exchange.

annaf-dev avatar Sep 03 '19 11:09 annaf-dev

If I recall correctly, the switch -DoNotCopyFields means that even the Standard Fields will not be copied. If you remove the switch does it copy the workflow fields?

michaellwest avatar Sep 03 '19 15:09 michaellwest

No, the Workflow state is not copied without the switch.

The fields Workflow and Default Workflow are shared so they are filled of course in the new language version. But the given workflow is not initialized in the new language - that's why the Workflow state is empty I assume.

I have taken two screenshots. The first one is the original language from which I create the new language versions. The workflow is correctly initialized here: spe_workflow-original

The second screenshot is from the newly created language version and looks the same with/without the -DoNotCopyFields switch: spe_workflow-not-initialized

Maybe that's a bit more helpful.

annaf-dev avatar Sep 04 '19 08:09 annaf-dev