-
Workflow not starting (state field is empty) when Versions.AddVersion after Sitecore upgrade from 6.5 to 8.1
November 23, 2016 Rodrigo Peplau 2
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:
Sitecore 6.5
When I run that on 6.5, which has 5 versions before:
The new version is created:
And the State is correctly filled:
Sitecore 8.1
However when I run it on 8.1, which previously had 39 versions:
The 40th version is created, but the State field is empty!
Solution
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);
Categories: Sitecore API, Upgrades, Workflow
Developers working in parallel with Continuous Integration builds for Dev and QA ERROR [Content Testing]: Cannot find PhantomJS executable at ' (...) /data/tools/phantomjs/phantomjs.exe'. Aborting screenshot generation.
2 thoughts on “Workflow not starting (state field is empty) when Versions.AddVersion after Sitecore upgrade from 6.5 to 8.1”
Leave a Reply Cancel reply
Localization
Recent Posts
Recent Comments
- NAVAN on Automatic Sitecore NuGet upgrades with Powershell
- Hedipo S Menezes on Corey Peplau wrote this - WFFM conflict with Unity DI and a lesson on how Sitecore community is so amazing
- Rodrigo Peplau on ERROR [Content Testing]: Cannot find PhantomJS executable at ' (...) /data/tools/phantomjs/phantomjs.exe'. Aborting screenshot generation.
- Fred on ERROR [Content Testing]: Cannot find PhantomJS executable at ' (...) /data/tools/phantomjs/phantomjs.exe'. Aborting screenshot generation.
- Rodrigo Peplau on Language specific MediaProvider breaking icons at Media Library
Archives
- February 2022
- December 2021
- November 2021
- March 2021
- July 2020
- February 2020
- September 2019
- July 2019
- April 2019
- March 2019
- December 2018
- February 2018
- January 2018
- November 2017
- September 2017
- August 2017
- July 2017
- March 2017
- February 2017
- November 2016
- September 2016
- August 2016
- July 2016
- April 2016
- November 2015
- September 2015
- July 2015
- April 2015
- March 2015
- February 2015
Categories
- Actions
- Active Directory
- Analytics
- Architecture
- Bug fixing
- CDP/Personalize
- Content Edition Experience
- Continuous Integration
- Dev
- Development
- Environments
- Experience Editor
- Experience Forms
- Front-end
- Health Check builds
- Helix
- How To
- LDAP
- MVP
- MVP Summit
- Phantom JS
- Powershell
- QA
- Richtext Editor
- Rules
- Security Provider
- SIF
- Sitecore 9
- Sitecore API
- Sitecore Community
- Sitecore Modules
- Sitecore Rocks
- Sitecore Rule Processor
- Sitecore Symposium
- SPE
- SPEAK
- SUG
- Support Ticket
- TDS
- Team City
- Uncategorized
- Upgrades
- Visual Studio
- WFFM
- Workflow
- XConnect
- xDB
Just curious did you try to wrap your .AddVersion() with try catch suggested in the link below – might work withouth having to do your workflow hack – haven’t tried it, just a thought:
http://blog.boro2g.co.uk/sitecore-addversion-returns-null/
Yes we tried that, however the issue was something else. Believe it or not, during the upgrade, the site definition we were using at the project 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.
The most funny is the guys at Sitecore’s Helpdesk also struggled a bit till they found out the issue.