<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sitecore Xperiences &#187; Workflow</title>
	<atom:link href="https://blog.peplau.com.br/category/workflow/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.peplau.com.br</link>
	<description>The things I&#039;ve seen as a Sitecore Professional</description>
	<lastBuildDate>Sun, 09 Mar 2025 21:54:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.41</generator>
	<item>
		<title>Workflow not starting (state field is empty) when Versions.AddVersion after Sitecore upgrade from 6.5 to 8.1</title>
		<link>https://blog.peplau.com.br/workflow-not-starting-state-field-is-empty-when-versions-addversion-after-sitecore-upgrade-from-6-5-to-8-1/</link>
		<comments>https://blog.peplau.com.br/workflow-not-starting-state-field-is-empty-when-versions-addversion-after-sitecore-upgrade-from-6-5-to-8-1/#comments</comments>
		<pubDate>Wed, 23 Nov 2016 22:19:18 +0000</pubDate>
		<dc:creator><![CDATA[Rodrigo Peplau]]></dc:creator>
				<category><![CDATA[Sitecore API]]></category>
		<category><![CDATA[Upgrades]]></category>
		<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">http://blog.peplau.com.br/?p=492</guid>
		<description><![CDATA[<div class="lr_horizontal_share" data-share-url="https://blog.peplau.com.br/workflow-not-starting-state-field-is-empty-when-versions-addversion-after-sitecore-upgrade-from-6-5-to-8-1/"></div>UPDATE: A ticket at Sitecore Helpdesk demonstrated the issue happened to be something else. During the upgrade, the site definition we&#8217;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=&#8221;true&#8221; then you don&#8217;t need [&#8230;]]]></description>
				<content:encoded><![CDATA[<blockquote><p><strong>UPDATE:</strong> A ticket at Sitecore Helpdesk demonstrated the issue happened to be something else. During the upgrade, the site definition we&#8217;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.</p>
<p>If your site does have enableWorlflow=&#8221;true&#8221; then you don&#8217;t need to manually start workflows as shown in this article</p>
</blockquote>
<p>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.</p>
<p><span style="font-weight: 400;">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.</span></p>
<p><span style="font-weight: 400;">And I then discovered it was Sitecore that changed the way how the API acts&#8230; 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.</span></p>
<p><span style="font-weight: 400;">The code was getting an item by it’s ID, adding a version and printing the number of the newly created version:</span></p>
<p><a href="http://blog.peplau.com.br/wp-content/uploads/Workflow-not-starting-1.png"><img class="alignnone size-full wp-image-493" src="http://blog.peplau.com.br/wp-content/uploads/Workflow-not-starting-1.png" alt="Workflow not starting - 1" width="557" height="183" /></a></p>
<h2>Sitecore 6.5</h2>
<p><strong><span style="font-weight: 400;">When I run that on 6.5, which has 5 versions before:</span></strong></p>
<p><a href="http://blog.peplau.com.br/wp-content/uploads/Workflow-not-starting-2.png"><img class="alignnone size-full wp-image-494" src="http://blog.peplau.com.br/wp-content/uploads/Workflow-not-starting-2.png" alt="Workflow not starting - 2" width="407" height="185" /></a></p>
<p><strong><span style="font-weight: 400;">The new version is created:</span></strong></p>
<p><a href="http://blog.peplau.com.br/wp-content/uploads/Workflow-not-starting-3.png"><img class="alignnone size-full wp-image-495" src="http://blog.peplau.com.br/wp-content/uploads/Workflow-not-starting-3.png" alt="Workflow not starting - 3" width="406" height="195" /></a></p>
<p><strong><span style="font-weight: 400;">And the State is correctly filled:</span></strong></p>
<p><a href="http://blog.peplau.com.br/wp-content/uploads/Workflow-not-starting-4.png"><img class="alignnone size-full wp-image-496" src="http://blog.peplau.com.br/wp-content/uploads/Workflow-not-starting-4.png" alt="Workflow not starting - 4" width="517" height="156" /></a></p>
<h2>Sitecore 8.1</h2>
<p><strong><span style="font-weight: 400;">However when I run it on 8.1, which previously had 39 versions:</span></strong></p>
<p><a href="http://blog.peplau.com.br/wp-content/uploads/Workflow-not-starting-5.png"><img class="alignnone size-full wp-image-497" src="http://blog.peplau.com.br/wp-content/uploads/Workflow-not-starting-5.png" alt="Workflow not starting - 5" width="496" height="114" /></a></p>
<p><strong><span style="font-weight: 400;">The 40th version is created, but the State field is empty!</span></strong></p>
<p><a href="http://blog.peplau.com.br/wp-content/uploads/Workflow-not-starting-6.png"><img class="alignnone size-full wp-image-498" src="http://blog.peplau.com.br/wp-content/uploads/Workflow-not-starting-6.png" alt="Workflow not starting - 6" width="462" height="178" /></a></p>
<h2><strong>Solution</strong></h2>
<p><span style="font-weight: 400;">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:</span></p>
<pre><span style="font-weight: 400;">Item newVersion = myItem.Versions.AddVersion();
</span>
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)
<strong><span style="font-weight: 400;">    workflow.Start(newVersion);</span></strong></pre>
]]></content:encoded>
			<wfw:commentRss>https://blog.peplau.com.br/workflow-not-starting-state-field-is-empty-when-versions-addversion-after-sitecore-upgrade-from-6-5-to-8-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
