Question

I have got created a list workflow in SharePoint Designer for a SharePoint Online Site Collection. Now I want to export this workflow and import it automatically to a new site collection during / after provisioning.

I found a PnP-PowerShell Cmd to export and import workflows. The export works fine, but when I want to import the workflow, a exception is shown.

PowerShell Code (QAZI MOBEEN - Export/Import SharePoint Designer Workflows using PowerShell):

Connect-PnPOnline -Url $Url -Credentials $cred

Write-Host " "
Write-Host "Connected successfully to: $($Url)" -ForegroundColor Yellow

$ctx = Get-PnPContext
$parentContentTypeId = $null

$wf = Get-PnPWorkflowDefinition -Name $WFDefinitionName

if ($wf -eq $null)
{
    # Load workflow definition
    Publish-WorkflowDefinition (Get-PnPContext) $FilePath $WFDefinitionName

    Add-PnPWorkflowSubscription -Name $WFDefinitionName -DefinitionName $WFDefinitionName -List "Dokumente" -HistoryListName "Workflow History" -TaskListName "Aufgaben" -StartOnCreated
}
else
{
    Write-Host "Workflow definition $($WFDefinitionName) already exists.." -ForegroundColor Yellow
}

The error code is the following:

Add-PnPWorkflowSubscription : Der Objektverweis wurde nicht auf eine
Objektinstanz festgelegt.
In C:\Users\xxx\source\Workspaces\Dev\src\AddIns\Import.ps1:33 Zeichen:5
+     Add-PnPWorkflowSubscription -Name $WFDefinitionName -DefinitionNa ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Add-PnPWorkflowSubscription], N
   ullReferenceException
    + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Work
   flows.AddWorkflowSubscription

Because of this interruption the workflow is published as "reusable" workflow instead of list workflow.

I do not get the wrong params in this line:

Add-PnPWorkflowSubscription -Name $WFDefinitionName -DefinitionName $WFDefinitionName -List "Dokumente" -HistoryListName "Workflow History" -TaskListName "Aufgaben" -StartOnCreated

Do you have any ideas to solve this issue?

Was it helpful?

Solution 2

I solved my problem.

If someone gets the same issue, you have to look in your xaml-file and replace GUID from your list(s). Afterwards everything works and the workflow will be a list workflow

OTHER TIPS

You could export and import the workflow by SharePoint designer like the picture below.

enter image description here

For more detailed information, refer to the article below.

Export-Import SharePoint Designer Workflow.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top