0

I have a site collection of type team site inside my SharePoint server 2013, where inside this site collection I did the following:-

  • I publish a workflow globally, using SharePoint designer 2013.
  • I associated a site content type with this global workflow, as follow :-

enter image description here

when i edit the workflow i will get this, and everything is working as expected .:-

enter image description here

But now as part of our backup testing, I took a backup of this site collection, and I restore it on a new server.. but I faced these issues on the restored site collection:-

  • When I access the workflow settings for the content type, I found that that there are two versions of the workflow (un-like the above picture):-

enter image description here

  • And when I click on the latest version to edit it, I faced a problem is that the global workflow is not there inside the workflow template list, and if I try to edit the workflow I will get a message “please select a workflow temple”:-

enter image description here

So I publish the global workflow on the restored site collection, after that the workflow appear on the workflow template list, but when I try to edit the workflow , I get the following error :-

Sorry, something went wrong There is already a workflow association with this name 'Supplier Contract Send Email and Update Contract Status'.

Technical Details

Can anyone advice on this ?

Now if on the restored site collection I remove the workflow from the content type, publish the global work flow, and associate the content type with the workflow , everything will work well,, but I am not sure why this did not work from the beginning. Now let say we have 20 global workflows, and we restore a site collection , then do we need to re-configure the global workflows & associate them with the content type ?

  • How did you backup/restore you site collection ? – JayHell Feb 11 '16 at 19:54
  • Is the patch level between servers the same? – SkinnyE Feb 17 '16 at 14:29
1

I also have that "Something went wrong..." every time I tried to run a workflow from a restored site collection. My solution was to republish all of my 50+ workflows with SharePoint Designer, and re-associate all of the reusable workflows with each list in the list settings.

That was a tedious job, so I resulted in creating two PowerShell scripts to do the republishing and resubscribing of workflows. I hope that helps.


#--------Republish Workflows.ps1

Clear-Host
Write-Host -ForegroundColor Green $MyInvocation.MyCommand.Name
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

function RepublishWorkflows($siteName) {
    $web = Get-SPWeb -Identity "http://$(hostname)/sites/$siteName" -ErrorAction SilentlyContinue
    if($web) {
        $wfm = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($web) 
        $depService = $wfm.GetWorkflowDeploymentService()
        $wfsubService = $wfm.GetWorkflowSubscriptionService()
        $wfDefs = $depService.EnumerateDefinitions($false)

        foreach($wfDef in $wfDefs) {
            $DefinitionId = $depService.SaveDefinition($wfDef)
            $depService.PublishDefinition($wfDef.id)
            if($wfDef.Properties.ContainsKey("SubscriptionId")) {
                $sub = $wfsubService.GetSubscription($wfDef.Properties["SubscriptionId"].Trim("{}"))
                $SubscriptionId = $wfSubService.PublishSubscription($sub)
            }else {
                $SubscriptionId = @{Guid="None"} #No SubscriptionId in definition (Reusable Workflow)
            }
            Write-Host ("{0,-75}{1,-20}{2,-45}{3,-0}" -f $wfDef.DisplayName, $siteName, $DefinitionId.Guid, $SubscriptionId.Guid)
        }
    }else {
        Write-Host -ForegroundColor Yellow "Site $siteName does not exist"
    }
}

Write-Host ""
Write-Host ("{0,-75}{1,-20}{2,-45}{3,-0}" -f "WorkflowName", "SiteName", "DefinitionId", "SubscriptionId")
Write-Host ("{0,-75}{1,-20}{2,-45}{3,-0}" -f "------------", "--------", "------------", "--------------")

RepublishWorkflows "MySite"

#--------Resubscribe Reusable Workflows.ps1

Clear-Host
Write-Host -ForegroundColor Green $MyInvocation.MyCommand.Name
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

function AddSubscription($listName, $workflow) {
    $list = $Global:web.Lists["$listName"]
    $wfTaskList = $Global:web.Lists[$workflow.TaskList]
    $wfHistoryList = $Global:web.Lists[$workflow.HistoryList]

    $wfDef = $Global:depService.EnumerateDefinitions($false) | where {$_.DisplayName -match $workflow.DefinitionName}

    #Create Workflow Subscription 
    $sub = New-object Microsoft.SharePoint.WorkflowServices.WorkflowSubscription
    $sub.DefinitionId = $wfDef.Id #{this is the id of the WorkflowDefinition}
    $sub.Enabled = $true
    $sub.Name = $workflow.SubscriptionName

    #Build start options
    $startOptions = New-Object System.Collections.ObjectModel.Collection[System.String]
    #$startOptions.Add("ItemAdded") #When item added
    #$startOptions.Add("ItemUpdated") #When item updated
    $startOptions.Add("WorkflowStart") #Allow manual start
    $sub.EventTypes = $startOptions

    $sub.SetProperty("HistoryListId", $wfHistoryList.Id)
    $sub.SetProperty("TaskListId", $wfTaskList.Id)

    Try {
        $devnull = $Global:wfSubService.PublishSubscriptionForList($sub, $list.Id)
    }Catch {
        if($_.Exception.InnerException -match "Microsoft.Workflow.Client.ActivityNotFoundException") {
            Write-Host -ForegroundColor Yellow 'Please run "Republish Workflows.ps1" before executing this script.'
             Exit 0
        }else {
            throw
        }
    }
}

function DelSubscription($listName, $workflow) {
    $list = $Global:web.Lists["$listName"]
    $tmp = $Global:wfsubService.EnumerateSubscriptions() | where {$_.Name -match $workflow.SubscriptionName -and $_.EventSourceId -eq $list.ID}
    if($tmp) {
        if($tmp.Count -eq 1) {
            $Global:wfsubService.DeleteSubscription($tmp[0].Id)
        }else {
            Write-Host "............ More than one Subscription"
        }
    }
}

$Workflow1 = @{DefinitionName="MyReusable1";SubscriptionName="Test Workflow 1";TaskList="Workflow Tasks";HistoryList="Workflow History"}
$Workflow2 = @{DefinitionName="MyReusable2";SubscriptionName="Test Workflow 2";TaskList="Workflow Tasks";HistoryList="Workflow History"}

$listNameArray = "MyList1","MyList2"

function ReassociateReusableWorkflows($siteName) {
    $Global:web = Get-SPWeb "http://$(hostname)/sites/$siteName" -ErrorAction SilentlyContinue

    if($Global:web) {

        $wfm = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($web) 
        $Global:depService = $wfm.GetWorkflowDeploymentService()
        $Global:wfsubService = $wfm.GetWorkflowSubscriptionService()

        foreach($listName in $listNameArray) {
            DelSubscription $listName $Workflow1
            DelSubscription $listName $Workflow2

            AddSubscription $listName $Workflow1
            AddSubscription $listName $Workflow2

            Write-Host ("{0,-70}{1,-20}{2,0}" -f $listName, $siteName ,"...done")
        }
    }else {
        Write-Host -ForegroundColor Yellow "Site $siteName does not exist"
    }
}

Write-Host ""
Write-Host ("{0,-70}{1,-20}" -f "SubscriptionName","SiteName")
Write-Host ("{0,-70}{1,-20}" -f "----------------","--------")

ReassociateReusableWorkflows "MySite"

-1

A SharePoint 2013 Workflow is not stored in the content database therefore when you do a backup of a Site Collection and restore it on another server, you have to save all the 2013 workflows as a template, upload and activate them under

/_catalogs/solutions/Forms/AllItems.aspx

and activate them as a feature on your site.

  • are you talking about global workflows or any workflow? because i have many list workflows and they are transferred using backup & restore...but i face this problem with global workflow,, also the global workflow will be restored,, but will not be published ....!! so not sure if your reply is valid .. – john Gu Feb 11 '16 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.