Wednesday, August 7, 2013

Migration and Task Forms

The problem

We migrated a SharePoint 2007 site collection to SharePoint 2010, using the database attach method. This site collection contains a custom workflow with multiple task forms. After the migration, we found that one of the fields in the completed task forms is blank, even though it was a mandatory field that was indeed completed before the migration.

The solution

First of all, we needed to make sure that the data was there. The completed task form data is stored in the task's ExtendedProperty. So, we ran this script and made sure that the correct attribute was there:



cls

$tasks = $w.Lists["Tasks"]
$iscs  = $tasks.Items | Where-Object { $_.Title -eq "Some task on Some List Item."}
$iscs | % {
Write-Host " "
$_.Title
$_["ExtendedProperties"]
}

After we found that the data was stored correctly, the next task was to make sure that the InfoPath form was displaying this field correctly. Unfortunately, the InfoPath 2010 form had some problems with this field and would not display its value, even though the task's ItemMetadata.xml was perfectly correct.

The solution involved renaming the field in the InfoPath form, and then changing the migrated data so that the field is mentioned by its new name. Here is the PowerShell script that does the trick.

cls

$site = Get-SPSite "
https://main.myveryownsite.com/sites/somesite"

$webs = $site.AllWebs | Where-Object { $_.IsRootWeb -ne $true -and $_.WebTemplate.StartsWith("STS")} 

foreach ($web in $webs)
{
    $web.AllowUnsafeUpdates = $true

    Write-Host "Processing " $web.Url ", web template:" $web.WebTemplate
   
    $web.Lists | Where-Object { $_.BaseTemplate -eq [Microsoft.SharePoint.SPListTemplateType]::Tasks -and $_.Fields.ContainsField("ExtendedProperties") }  | % {
        Write-Host "  Task list" $_.Title " in web " $_.ParentWebUrl " contains ExtendedProperties - investigating..."
  
        $listItems = $_.Items
  
        $listItems | % {
       
                try
                {
                    $itemEP = $_["ExtendedProperties"]
             
                    if ($itemEP -ne $null -and $itemEP.Contains("ows_AuthoritiesComments"))
                    {
                        if ($_.Title.StartsWith("ISC Chairperson task on"))
                        {
                            $itemEP = $itemEP.Replace("ows_OldFieldName", "ows_NewFieldName");
                                                                                      
                            $_["ExtendedProperties"] = $itemEP
                  
                            Write-Host "      Trying to update " $_.Title " extended properties"
                            $_.SystemUpdate($false)
                            Write-Host "      Finished updating " $_.Title " extended properties"
                        }
                    }
                }
                catch [Exception] {
                        Write-Error $_.Exception.ToString()
                    }
            }
        }
        $web.AllowUnsafeUpdates = $false
        $web.Dispose()
}

Worked like a charm!


No comments:

Post a Comment