<?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; Upgrades</title>
	<atom:link href="https://blog.peplau.com.br/category/upgrades/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>Automatic Sitecore NuGet upgrades with Powershell</title>
		<link>https://blog.peplau.com.br/automatic-sitecore-nuget-upgrades-with-powershell/</link>
		<comments>https://blog.peplau.com.br/automatic-sitecore-nuget-upgrades-with-powershell/#comments</comments>
		<pubDate>Tue, 02 Nov 2021 02:05:18 +0000</pubDate>
		<dc:creator><![CDATA[Rodrigo Peplau]]></dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Upgrades]]></category>

		<guid isPermaLink="false">http://blog.peplau.com.br/?p=894</guid>
		<description><![CDATA[<div class="lr_horizontal_share" data-share-url="https://blog.peplau.com.br/automatic-sitecore-nuget-upgrades-with-powershell/"></div>One of the most tedious tasks in any Sitecore upgrade is to update your NuGet references. If your projects have so many NuGet references on packages.config, and in special with Helix solutions, updating everything manually can take you several hours. To the rescue, I&#8217;ve created this Powershell Script, which you can use to save your precious time. What [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>One of the most tedious tasks in any Sitecore upgrade is to update your NuGet references. If your projects have so many NuGet references on <em>packages.config</em>, and in special with Helix solutions, updating everything manually can take you several hours.</p>
<p>To the rescue, I&#8217;ve created this <a href="https://gist.github.com/peplau/450a72767b8a15a61db552560bc8bf9f" target="_blank">Powershell Script</a>, which you can use to save your precious time.</p>
<p>What you need to download:</p>
<ul>
<li>The <a href="https://gist.github.com/peplau/450a72767b8a15a61db552560bc8bf9f" target="_blank">Powershell Script</a> itself</li>
<li>The CSV file with all Sitecore references from <a href="http://www.stockpick.nl/english/sitecore-nuget-dependencies-in-sitecore-101/" target="_blank">this article</a> &#8211; Direct link to the <a href="http://www.stockpick.nl/1/NuGet%20Sitecore.Platform.Assemblies%2010.1.0%20rev.%20005207.csv" target="_blank">CSV file itself is here</a>.<br />
This file is valid for Sitecore 10.1 &#8211; if you need a different version, you will have to prepare and use a different CSV file (Read the article to learn more)</li>
</ul>
<p>Steps to update each project in your solution:</p>
<ul>
<li><strong>Step 1</strong> &#8211; If your upgrade requires, update your Project to the target .NET Framework</li>
<li><strong>Step 2</strong> &#8211; Get the NuGet commands to update your project.</li>
<li><strong>Step 3</strong> &#8211; Run the NuGet commands at the Package Manager Console of Visual Studio</li>
</ul>
<p>It is recommended to update the references gradually, so you can detect and fix any issue as you continue.</p>
<p>In my experience, the following sequence produced good results:</p>
<ol>
<li>If your .NET Framework has changed due to the upgrade, re-install all references not used by Sitecore by running the following command:<br />
<blockquote><p>.\Update-PackagesFile.ps1 -Csv &#8220;C:\temp\NuGet Sitecore.Platform.Assemblies 10.1.0 rev. 005207.csv&#8221; -Packages &#8220;D:\Git\myproject\packages.config&#8221; -ProjectName &#8220;MyProject&#8221; -DumpUnknownReinstall $true</p></blockquote>
</li>
<li>Update the 3rd party references to the target versions, and using this command:<br />
<blockquote><p>.\Update-PackagesFile.ps1 -Csv &#8220;C:\temp\NuGet Sitecore.Platform.Assemblies 10.1.0 rev. 005207.csv&#8221; -Packages &#8220;D:\Git\myproject\packages.config&#8221; -ProjectName &#8220;MyProject&#8221; -DumpKnownReinstall $true</p></blockquote>
</li>
<li>Sometimes 3rd party reference versions didn&#8217;t change, but you still want to force them to reinstall.  If that&#8217;s your case, use the command:<br />
<blockquote><p>.\Update-PackagesFile.ps1 -Csv &#8220;C:\temp\NuGet Sitecore.Platform.Assemblies 10.1.0 rev. 005207.csv&#8221; -Packages &#8220;D:\Git\myproject\packages.config&#8221; -ProjectName &#8220;MyProject&#8221; -DumpKnownReinstall $true</p></blockquote>
</li>
<li>Finally, uninstall and re-install your Sitecore references (useful when migrating from earlier versions into SC10):<br />
<blockquote><p>.\Update-PackagesFile.ps1 -Csv &#8220;C:\temp\NuGet Sitecore.Platform.Assemblies 10.1.0 rev. 005207.csv&#8221; -Packages &#8220;D:\Git\myproject\packages.config&#8221; -ProjectName &#8220;MyProject&#8221; -TargetSitecore &#8220;10.1&#8221; -DumpSitecoreUpdates $true</p></blockquote>
<p>or simply update them with this command:</p>
<blockquote><p>.\Update-PackagesFile.ps1 -Csv &#8220;C:\temp\NuGet Sitecore.Platform.Assemblies 10.1.0 rev. 005207.csv&#8221; -Packages &#8220;D:\Git\myproject\packages.config&#8221; -ProjectName &#8220;MyProject&#8221; -TargetSitecore &#8220;10.1&#8221; -DumpSitecoreUpdates $true -KeepSitecoreLibs $true</p></blockquote>
</li>
</ol>
<p>&nbsp;</p>
<h3>Full description of parameters:</h3>
<ul>
<li><strong>Csv</strong> (mandatory) &#8211; Path to the CSV file</li>
<li><strong>Packages</strong> (mandatory) &#8211; Path to the packages.config file</li>
<li><strong>ProjectName</strong> (mandatory) &#8211; Project Name</li>
<li><strong>TargetSitecore</strong> &#8211; Target Sitecore version</li>
<li><strong>DumpUnknownReinstall</strong> &#8211; If $true =&gt; Will dump the Update-Package with -reinstall commands for libraries not used by Sitecore</li>
<li><strong>DumpKnownUpdates</strong> &#8211; If $true =&gt; Will dump the Update-Package commands for known libraries when versions doesn&#8217;t match</li>
<li><strong>DumpKnownReinstall</strong> &#8211; If $true =&gt; Will dump the Update-Package with -reinstall when versions are the same</li>
<li><strong>DumpSitecoreUpdates</strong> &#8211; If $true =&gt; Will dump the Update-Package for Sitecore.* libraries</li>
<li><strong>KeepSitecoreLibs</strong>
<ul>
<li>If $true  =&gt; then the Sitecore entries will NOT be uninstalled (Update)</li>
<li>If $false =&gt; then the Sitecore entries will be uninstalled and re-installed (useful when migrating from earlier versions into SC10)</li>
</ul>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://blog.peplau.com.br/automatic-sitecore-nuget-upgrades-with-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Language specific MediaProvider breaking icons at Media Library</title>
		<link>https://blog.peplau.com.br/language-specific-mediaprovider-breaking-icons-at-media-library/</link>
		<comments>https://blog.peplau.com.br/language-specific-mediaprovider-breaking-icons-at-media-library/#comments</comments>
		<pubDate>Tue, 14 Feb 2017 15:00:30 +0000</pubDate>
		<dc:creator><![CDATA[Rodrigo Peplau]]></dc:creator>
				<category><![CDATA[Bug fixing]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Support Ticket]]></category>
		<category><![CDATA[Upgrades]]></category>

		<guid isPermaLink="false">http://blog.peplau.com.br/?p=538</guid>
		<description><![CDATA[<div class="lr_horizontal_share" data-share-url="https://blog.peplau.com.br/language-specific-mediaprovider-breaking-icons-at-media-library/"></div>UPDATE: Kamruz Jaman has contributed with a comment for a simpler, less intrusive and more generalist solution:  Inside the GetMediaUrl method of your custom MediaProvider, check for the &#8220;Thumbnail&#8221; property of your MediaUrlOptions parameter. If it is true, make your code fall back to the base, such as: if (mediaOptions.Thumbnail) return base.GetMediaUrl(mediaItem, mediaOptions); During an upgrade from [&#8230;]]]></description>
				<content:encoded><![CDATA[<blockquote><p><strong>UPDATE: </strong>Kamruz Jaman has contributed with a comment for a simpler, less intrusive and more generalist solution:  Inside the GetMediaUrl method of your custom MediaProvider, check for the &#8220;Thumbnail&#8221; property of your MediaUrlOptions parameter. If it is true, make your code fall back to the base, such as:</p>
<p>if (mediaOptions.Thumbnail)<br />
return base.GetMediaUrl(mediaItem, mediaOptions);</p></blockquote>
<p>During an upgrade from Sitecore 6.5 to Sitecore 8.1 one issue were noticed at the Media Library: when a Media Item is uploaded, the icon appears broken.</p>
<p><a href="http://blog.peplau.com.br/wp-content/uploads/Broken-Icon.png"><img class=" size-full wp-image-539 alignnone" src="http://blog.peplau.com.br/wp-content/uploads/Broken-Icon.png" alt="Broken Icon" width="703" height="117" /></a></p>
<p>A custom MediaProvider is used at this build to modify the way Sitecore generates Media Item urls. All it does is to add the language at beginning of the media URL so we can have language-specific media items. This is important to allow the same Media Item (etc: an image or PDF) to be served in multiple languages.</p>
<h2>Root cause</h2>
<p>When a media item is uploaded to the Media Library, Sitecore will fill the &#8220;Icon&#8221; field with the URL of the media item itself. Because of the custom MediaProvider, language is being added to the beginning of the generated URL. Apparently that was not a problem in Sitecore 6.5, but things seems to have changed at Sitecore 8.</p>
<h2>Technical explanation by Sitecore</h2>
<p>A Support Ticket #476256 were created to allow further investigation from Sitecore on this issue. According to the technical team:</p>
<blockquote><p>&#8220;The behavior you reported is expected as tree node icons are rendered by <em>Sitecore.Shell.Applications.ContentManager.Sidebars.Tree.RenderIcon(Item item)</em> method which does not use language definition, embedded to URL, to resolve item language. So when the Icon field contains URL with language definition embedded, it breaks the method functionality and leads to incorrect resolution of the item&#8217;s icon.</p>
<p>When you have versioned media item, the icon is rendered for specific language automatically even when language is not specified deliberately. For instance, if you have media item with two language versions and different images for each language, and use -/media/ItemGUID.ashx?h=16&amp;thn=1&amp;w=16 string in the Icon field, language specific icon will be rendered when you switch the language in the Content Editor.&#8221;</p></blockquote>
<p>This explains the causes but doesn&#8217;t fix the issue: <span style="text-decoration: underline;">how can we skip or bypass the custom MediaProvider, avoiding the language to be added to the URL when the &#8220;Icon&#8221; field is filled?</span></p>
<h2>Solution</h2>
<p>In order to fix that we will need to extend and override the <em>Sitecore.Resources.Media.Media</em> class, responsible for the upload and update of metadata when a Media Item is uploaded to the Media Library, then modify all Media Types to use your class instead of the original.</p>
<h3>Step 1 &#8211; Extend the Media class</h3>
<p>This is going to be responsible for removing the language from the URL when a Media Item is uploaded. In bold you see the code responsible for that, rest is basically native code to ensure compliance with default Sitecore behavior.</p>
<pre>using Sitecore;
using Sitecore.Configuration;
using Sitecore.Data.Items;
using Sitecore.Data.Proxies;
using Sitecore.Diagnostics;
using Sitecore.Resources.Media;
using Sitecore.SecurityModel;

namespace CustomMediaProvider
{
  public class Media : Sitecore.Resources.Media.Media
  {
    public override Sitecore.Resources.Media.Media Clone()
    {
      return new Media();
    }

    public override void UpdateMetaData(MediaStream mediaStream)
    {
      Assert.ArgumentNotNull(mediaStream, "mediaStream");
      var innerItem = MediaData.MediaItem.InnerItem;
      if (!innerItem.Paths.IsMediaItem) return;
      using (new EditContext(innerItem, SecurityCheck.Disable))
      {
        innerItem["extension"] = mediaStream.Extension;
        innerItem["mime type"] = mediaStream.MimeType;
        innerItem["size"] = mediaStream.Length.ToString();
        if (Settings.Media.AutoSetAlt)
        {
          innerItem["Alt"] = innerItem.Name;
        }
        var shellOptions = MediaUrlOptions.GetShellOptions();
        shellOptions.Thumbnail = true;
        shellOptions.Height = 0x10;
        shellOptions.Width = 0x10;
        var realItem = ProxyManager.GetRealItem(innerItem, true);
<strong>        // CODE ADDED TO REMOVE LANGUAGE FROM URL WHILE UPLOADING</strong>
<strong>        var iconUrl = MediaManager.GetMediaUrl(realItem, shellOptions);</strong>
<strong>        var prefix = "/" + Context.Language.Name + "/";</strong>
<strong>        if (iconUrl.StartsWith(prefix)) iconUrl = iconUrl.Replace(prefix, "");</strong>
        innerItem.Appearance.Icon = iconUrl;
      }
    }
  }
}</pre>
<h3>Step 2 &#8211; Register the Media class to all Media Types</h3>
<p>This is the painful part: we will need to register our class to every Media Type we want to cover. There is no easy way for that other than adding a node for each Media Type, paying attention to the correct way for patching that specific node (some nodes may have a Media class already defined and thus needs correct patching, others don&#8217;t).</p>
<pre>&lt;configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"&gt;
 &lt;sitecore&gt;
 &lt;mediaLibrary&gt;
 &lt;!-- This is our Custom MediaProvider causing all the trouble --&gt;
 &lt;mediaProvider&gt;
 &lt;patch:attribute name="type"&gt;CustomMediaProvider.MediaProvider,CustomMediaProvider&lt;/patch:attribute&gt;
 &lt;/mediaProvider&gt;
 &lt;!-- And here goes our custom Media class being attached to several Media Types --&gt;
 &lt;mediaTypes&gt;
 &lt;mediaType name="Any" extensions="*"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider" patch:instead="*[@type='Sitecore.Resources.Media.Media, Sitecore.Kernel']"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="AVI video" extensions="avi"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="Windows Bitmap image" extensions="bmp, dib"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider" patch:instead="*[@type='Sitecore.Resources.Media.ImageMedia, Sitecore.Kernel']"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="Flash" extensions="swf"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider" patch:instead="*[@type='Sitecore.Resources.Media.SwfMedia, Sitecore.Kernel']"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="Flash video" extensions="flv"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="GIF image" extensions="gif"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider" patch:instead="*[@type='Sitecore.Resources.Media.ImageMedia, Sitecore.Kernel']"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="HTML" extensions="htm,html,stm"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="JPEG image" extensions="jpg, jpeg, jpe, jfif"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider" patch:instead="*[@type='Sitecore.Resources.Media.ImageThumbnailGenerator, Sitecore.Kernel']"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="MP3" extensions="mp3"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider" patch:instead="*[@type='Sitecore.Resources.Media.Mp3Media, Sitecore.Kernel']"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="MP4 video" extensions="mp4"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="PDF file" extensions="pdf"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="PNG image" extensions="png"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider" patch:instead="*[@type='Sitecore.Resources.Media.ImageMedia, Sitecore.Kernel']"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="SVG image" extensions="svg"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider" patch:instead="*[@type='Sitecore.Resources.Media.SvgMedia, Sitecore.Kernel']"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="QuickTime movie" extensions="mov, qt"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="TIFF image" extensions="tiff, tif"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider" patch:instead="*[@type='Sitecore.Resources.Media.ImageMedia, Sitecore.Kernel']"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="Zip file" extensions="zip"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider" patch:instead="*[@type='Sitecore.Resources.Media.ZipMedia, Sitecore.Kernel']"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="Video for Adobe Flash Player" extensions="f4v"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="Windows Media video" extensions="WMV"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="Word document" extensions="doc"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="Word 2007 document" extensions="docx"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="PPTX File" extensions="pptx"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="PPT File" extensions="ppt"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="XLSX File" extensions="xlsx"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;mediaType name="XLS File" extensions="xls"&gt;
 &lt;prototypes&gt;
 &lt;media type="CustomMediaProvider.Media, CustomMediaProvider"/&gt;
 &lt;/prototypes&gt;
 &lt;/mediaType&gt;
 &lt;/mediaTypes&gt;
 &lt;/mediaLibrary&gt;
 &lt;/sitecore&gt;
&lt;/configuration&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>https://blog.peplau.com.br/language-specific-mediaprovider-breaking-icons-at-media-library/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<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>
