<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="https://blog.aabech.no/rss/xslt"?>
<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Lars-Erik's blog</title>
    <link>https://blog.aabech.no/</link>
    <description>Ramblings about Umbraco, .net and JavaScript development. With a sprinkle of other stuff.</description>
    <generator>Articulate, blogging built on Umbraco</generator>
    <item>
      <guid isPermaLink="false">1212</guid>
      <link>https://blog.aabech.no/archive/migrating-umbraco-forms-from-7-to-modern/</link>
      <category>umbraco</category>
      <title>Migrating Umbraco Forms from 7 to modern</title>
      <description>&lt;h3&gt;No migration, no cry&lt;/h3&gt;
&lt;p&gt;There is no uSync Migrations extension for moving forms from 7 to modern.
There isn't even a uSync Forms for V7.
However the serialization format for forms on disk didn't change (much?) from 7 to 8, so we can do a trick. (Thanks to Kevin for the tip)&lt;br /&gt;
We can do 7 to 8, then 8 to modern.&lt;br /&gt;
This applies to files. I have not tried with the forms in database method, but that should be possible to do with database migrations from 7 to 8.&lt;/p&gt;
&lt;h3&gt;7 to 8&lt;/h3&gt;
&lt;p&gt;Create an empty V8 site and install the following nuget packages:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;UmbracoForms&lt;/li&gt;
&lt;li&gt;uSync.Forms&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To &amp;quot;migrate&amp;quot; your forms from 7 to 8 you just copy the files over. 😁&lt;br /&gt;
Your source files should be in &lt;code&gt;/App_Data/UmbracoForms/Data&lt;/code&gt;.&lt;br /&gt;
The target should be the same in a V8 site.&lt;/p&gt;
&lt;p&gt;When your files are copied you're ready to go into the backoffice.&lt;br /&gt;
Go to Settings \ uSync and click Export.&lt;/p&gt;
&lt;p&gt;You should now have uSync files for the forms under &lt;code&gt;/uSync/v8/Forms&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;8 to modern&lt;/h3&gt;
&lt;p&gt;Install uSync.Forms in your modern site.&lt;br /&gt;
Copy your uSync forms files from the V8 site into &lt;code&gt;/uSync/v9/Forms&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The uSync files will have prevalues in a &lt;code&gt;parsedPreValues&lt;/code&gt; field instead of &lt;code&gt;preValues&lt;/code&gt;.&lt;br /&gt;
uSync Forms import in modern does not like this.&lt;br /&gt;
So I made a small powershell script that does the necessary &amp;quot;migration&amp;quot;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;param(
    $path
)

$files = Get-ChildItem -Path $path -File

$files | % {
    $fileInfo = $_
    $doc = [xml](Get-Content $fileInfo.FullName)
    $pageNode = $doc.DocumentElement.SelectSingleNode(&amp;quot;Pages&amp;quot;)
    $origCData = $pageNode.FirstChild
    $pages = [array]($origCData.InnerText | ConvertFrom-Json)

    $results = $pages | % {
        $page = $_
        $page.fieldSets | % {
            $fieldSet = $_
            $fieldSet.containers | % {
                $container = $_
                $container.fields | % {
                    $field = $_
                    if ($field.parsedPrevalues.Length -gt 0) {
                        $field.preValues = $field.parsedPrevalues
                    }
                    $field.psobject.Properties.Remove(&amp;quot;parsedPreValues&amp;quot;)
                }
            }
        }
    }

    $cdata = $doc.CreateCDataSection((ConvertTo-Json -depth 99 -inputobject $pages))
    $replaced = $pageNode.ReplaceChild($cdata, $origCData)

    $doc.Save($fileInfo.FullName)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I called the script &lt;code&gt;fix-usync-forms.ps1&lt;/code&gt; and we can call it as such:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;./fix-usync-forms.ps1 [path-to-site]/uSync/v9/Forms&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;That's it!&lt;/p&gt;
&lt;p&gt;We can now go into the backoffice in our modern site.&lt;br /&gt;
Go to Settings \ uSync and click &amp;quot;Import&amp;quot; under Forms.&lt;/p&gt;
&lt;h3&gt;Success&lt;/h3&gt;
&lt;p&gt;Now all that's left is porting your potential code and views.&lt;/p&gt;
&lt;p&gt;Happy migrating! 🙃&lt;/p&gt;
</description>
      <pubDate>Wed, 28 Feb 2024 11:58:06 Z</pubDate>
      <a10:updated>2024-02-28T11:58:06Z</a10:updated>
    </item>
  </channel>
</rss>