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?

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.

  • Thanks for your reply and the idea to ex-/import wirkflows manual. But I need to import the workflow automatically during / after the provisioning of site collections. – Nick Delefski Sep 22 at 11:25
up vote 0 down vote accepted

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

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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