Hello,
I am trying to start a workflow on an item but I am having issues. Can someone help with the commands and the order of operation etc. for starting a workflow.
Start-PNPWorkflowInstance has subscription as a required parameter, however I am having trouble getting Get-PnPWorkflowSubscription to return anything other than the following error.
On-Prem 2013 environment.
Cannot invoke method or retrieve property from null object. Object returned by the following call stack is null. "GetWorkflowSubscriptionService
new Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager()
"
At H:\Documents\SharePoint\PowerShell\WIP\PnP_ReviewNotification_Library.ps1:54 char:13
+ Get-PnPWorkflowSubscription -Name $Workflowname -List $Li ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Get-PnPWorkflowSubscription], ServerException
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Workflows.GetWorkflowSubscription
#===================================================================================
#===================================================================================
$ErrorActionPreference = 1
# 0 = SilentlyContinue, 1 = Stop, 2 = Continue, 3 = Inquire, 4 = Ignore
#===================================================================================
# Variables
#===================================================================================
$Site = "http://mysite/personal/******/policy"
$Listname = "Documents"
$Workflowname = "ReviewNotification"
#Fields
$NotificationDate30 = "Notification_x0020_Date_x0020_30"
$CurrentDate = Get-Date
#===================================================================================
# Connect
#===================================================================================
function Connect () {
Connect-PnPOnline $Site -CurrentCredentials
Write-Host -ForegroundColor Green "Connected to: " -nonewline;
Write-Host -ForegroundColor White $Site
}
function Disconnect () {
Disconnect-PnPOnline
Write-Host -ForegroundColor Green "Stopped"
}
#===================================================================================
# Functions
#===================================================================================
# Start Review Notificaiton Workflow
function ReviewNotification() {
#Loop Items
$List = Get-PnPList $Listname
$Items = Get-PnPListItem -List $Listname
foreach ($Item in $Items) {
#Check Review Date
if ($Item[$NotificationDate30].Date -eq $CurrentDate.Date) {
Write-Host -ForegroundColor Yellow $Item["FileLeafRef"]
Write-Host -ForegroundColor Magenta "Date: " -nonewline;
Write-Host -ForegroundColor White $Item[$NotificationDate30].Date -nonewline;
Write-Host -ForegroundColor Green " Today!"
Get-PnPWorkflowSubscription -Name $Workflowname -List $List
Write-Host -ForegroundColor Green "Workflow Started"
} else {
Write-Host -ForegroundColor Yellow $Item["FileLeafRef"]
Write-Host -ForegroundColor Magenta "Date: " -nonewline;
Write-Host -ForegroundColor White $Item[$NotificationDate30].Date -nonewline;
Write-Host -ForegroundColor Red " Not Today!"
}
}
}
#===================================================================================
# Actions
#===================================================================================
Connect
ReviewNotification
Disconnect
Thanks
OK well this was probably obvious to some people, but this apparently only works if you have the 2013 workflow manager configured and not with 2010 workflows.