Can't set workflow and workflow state properties on sitecore items
Asked Answered
P

1

7

I am currently working on a project that requires me to set up a very simple sitecore workflow. I am running into some difficulties when modifying the existing items to use my new workflow. This is what i did:

The workflow creates a new version when a contentmanager starts editing an item and publishes the item when the submit button is clicked.

Sitecore workflow items

I added these workflow items to the standard values of my templates:

Workflow settings of standard values of templates

The next step would be to set the workflow settings on the already existing items. Luckily we can use sitecore-powershell to do this for us.

function SetWorkflow($item)
{
    $item.__Workflow = "{DE29E564-3157-4CAB-81B1-87DF2E983517}";
    $item."__Workflow state" = "{27633BF0-B76A-4450-A139-BA53F6943778}";
}

get-childitem . -recurse -Language * | foreach-object { SetWorkFlow($_) }

This script runs without errors.

Now the fun starts: When I opened the items I ran this script on the Workflow and Workflow state properties haven't changed. Weirdly enough, the editor says that the empty values are being inherited from the standard values, though the standard values are not empty, i have set these!

Workflow settings of the items

You'd say that the script maybe has failed and that no values have been set. Except when I look the values up in sitecore-powershell, i can see that the values are there.

get-childitem . -recurse -Language * | Format-Table Id, Language, __Workflow, "__Workflow state"

ID                                                          Language                                                    __Workflow                                                  __Workflow state
--                                                          --------                                                    ----------                                                  ----------------
{208D79B1-5B42-4713-A7F9-F2109588F639}                      en                                                          {DE29E564-3157-4CAB-81B1-87DF2E983517}                      {27633BF0-B76A-4450-A139-BA53F6943778}
{208D79B1-5B42-4713-A7F9-F2109588F639}                      nl-NL                                                       {DE29E564-3157-4CAB-81B1-87DF2E983517}                      {27633BF0-B76A-4450-A139-BA53F6943778}
{3F3B1132-02DA-4E75-928F-BDB8AED5C3CD}                      nl-NL                                                       {DE29E564-3157-4CAB-81B1-87DF2E983517}                      {27633BF0-B76A-4450-A139-BA53F6943778}
{8AF23DC5-E7FE-47E3-AC65-AA3D41D81F97}                      en                                                          {DE29E564-3157-4CAB-81B1-87DF2E983517}                      {27633BF0-B76A-4450-A139-BA53F6943778}
{8AF23DC5-E7FE-47E3-AC65-AA3D41D81F97}                      nl-NL                                                       {DE29E564-3157-4CAB-81B1-87DF2E983517}                      {27633BF0-B76A-4450-A139-BA53F6943778}

etc.etc.

I tried setting the workflow and workflow state properties on the items by hand. This works kinda, i can go through the workflow once. When a new version is added the workflow and workflow state properties default back to their 'empty' standard values which breaks the workflow for that item.

Does anyone know what's happening here? How can I set the workflow and workflow state properties once and for all?

Postdoctoral answered 9/3, 2015 at 15:20 Comment(0)
R
3

On the Standard Values of your base template, did you set the workflow on the Workflow field? It actually needs to be set on the Default workflow field. The other 3 fields are "current state" fields, i.e. it stores which stage of the workflow the item is currently in, these should be left blank in the your template and standard values.

More info from section 3.3.1 of the Sitecore Workflow Reference:

Assigning Workflows to Items

By default, items are not placed in a workflow when created. Sitecore only places items in a workflow if the “Initial” workflow is set for the corresponding data template standard values item. The Initial workflow corresponds to the Default Workflow field in the Standard Template.

Reena answered 9/3, 2015 at 15:33 Comment(5)
Glad to see you used PowerShell Extensions for it and the fact that it appears to be verifying its results. What worries me however is the fact that you wouldn't see them in the Content Editor. My question is whether this is still the case. A mistake I usually make when checking this is that I check the item I was calling the Get-ChildItem -Recurse on while the script would only work on its children. :) I'm not saying it's the case here, but I've run this scripts and Content Editor Shown has shown the results that you were expecting, just wondering why it would be different in your case.Equidistant
Oops... I think I've edited the response rather than adding my own comment... I'm really REALLY sorry about that :(Equidistant
Hi Adam, the sitecore content editor might not display the values set by the powershell script due to the __workflow and __workflow state field being these "current state" fields as described by jammykam. Sitecore powershell has always worked like a charm for my other powershell scripts. Thanks for creating this awesome tool!Postdoctoral
Thanks for the kind words. I just can't get it out of my mind though as to why you don't see the results. I've tested it locally using your script (only with my workflow ID's) and it's showing in Content Editor just fine. There is one more possibility - if you have multiple versions of the items the value might be set on a different version of the item, is that something that might be the case here?Equidistant
Hi Adam, sorry for the delayed response, I confirmed that there are indeed multiple versions of these items. I checked and the older versions were changed just fine.Postdoctoral

© 2022 - 2024 — McMap. All rights reserved.