UPDATE: A ticket at Sitecore Helpdesk demonstrated the issue happened to be something else. During the upgrade, the site definition we’re using got the attribute “enableWorkflow” removed, which in turn made the default value “false” take over, and that was causing ALL WORKFLOWS to be simply ignored.
If your site does have enableWorlflow=”true” then you don’t need to manually start workflows as shown in this article
After an upgrade, a certain code was simply not working as expected anymore. When you create a new version of an item (item.Versions.AddVersion), whose _Standard Values had a Default Workflow setup, the workflow simply was not starting, and thus the “State” field gets empty. The very same code, at the non-upgraded version, works perfectly.
Looking at the code, it was never touching Workflows, suggesting that Sitecore would be automatically handling the thing. Since it was an upgrade, I lost myself investigating for things I could have left behind: Pipelines, Scheduled Tasks, etc.
And I then discovered it was Sitecore that changed the way how the API acts… a change that made me struggle in for almost a week! And I just learned that when I decided to create a small script to run the same code on both 6.5 and 8.1 instances.
The code was getting an item by it’s ID, adding a version and printing the number of the newly created version:
When I run that on 6.5, which has 5 versions before:
The new version is created:
And the State is correctly filled:
However when I run it on 8.1, which previously had 39 versions:
The 40th version is created, but the State field is empty!
So what I had to do, to make the same code run correctly on 8.1, was to force the item thru the workflow after a new version is created. That screw hard to find, easy to twist:
Item newVersion = myItem.Versions.AddVersion(); var defaultWorkflow = newVersion.Fields[FieldIDs.DefaultWorkflow].Value; ID defaultWorkflowId; if (!ID.TryParse(defaultWorkflow, out defaultWorkflowId)) return; var workflow = newVersion.Database.WorkflowProvider.GetWorkflow(defaultWorkflowId.ToString()); if (workflow!=null) workflow.Start(newVersion);