工作流订阅服务不返回任何值

时间:2016-11-12 15:16:09

标签: sharepoint-2013 office365 powershell-v3.0 sharepoint-workflow

我正在尝试通过powershell csom模型启动SharePoint 2013工作流程。我浏览过并且使用相同的有希望的编码获得了许多链接。但就我而言,它不起作用。我已经尝试了内部sharepoint 2013和sharepoint在线,但没有一个解决。以下是代码:

Set-ExecutionPolicy Unrestricted

Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server   Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.WorkflowServices.dll"

# Specify tenant admin and site URL
$SiteUrl = "https://spoffice365.sharepoint.com/"
$ListName = "Test"
$UserName = "myusername"
$SecurePassword = Read-Host -Prompt "Enter password" -AsSecureString

# Connect to site
$ClientContext = New-Object   Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,   $SecurePassword)
 $ClientContext.Credentials = $credentials
  $ClientContext.ExecuteQuery()

  # Get List and List Items
  $List = $ClientContext.Web.Lists.GetByTitle($ListName)
  $ListItems = $List.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
 $ClientContext.Load($List)
 $ClientContext.Load($ListItems)
 $ClientContext.ExecuteQuery()

# Retrieve WorkflowService related objects
 $WorkflowServicesManager = New-Object Microsoft.SharePoint.Client.WorkflowServices.WorkflowServicesManager($ClientContext, $ClientContext.Web)
$WorkflowSubscriptionService =  $WorkflowServicesManager.GetWorkflowSubscriptionService()
 $WorkflowInstanceService =   $WorkflowServicesManager.GetWorkflowInstanceService()
$ClientContext.Load($WorkflowServicesManager)
$ClientContext.Load($WorkflowSubscriptionService)
$ClientContext.Load($WorkflowInstanceService)
$ClientContext.ExecuteQuery()
# Get WorkflowAssociations with List
$WorkflowAssociations =    $WorkflowSubscriptionService.EnumerateSubscriptionsByList($List.Id)
 $ClientContext.Load($WorkflowAssociations)
$ClientContext.ExecuteQuery()

# Prepare Start Workflow Payload
$Dict = New-Object 'System.Collections.Generic.Dictionary[System.String,System.Object]'

 # Loop List Items to Start Workflow
  For ($j=0; $j -lt $ListItems.Count; $j++){
  $msg = [string]::Format("Starting workflow {0}, on ListItemId {1}",  $WorkflowAssociations[0].Name, $ListItems[$j].Id)
Write-Host $msg
#Start Workflow on List Item
$Action =   $WorkflowInstanceService.StartWorkflowOnListItem($WorkflowAssociations[0],  $ListItems[$j].Id, $Dict)
$ClientContext.ExecuteQuery()
 }  

以下$ WorkflowAssociations在sharepoint 2013和sharepoint online中都不返回任何值,即使$ List.Id正确传递并验证列表已配置批准者工作流程,也始终为空。 < / p>

$WorkflowAssociations =    $WorkflowSubscriptionService.EnumerateSubscriptionsByList($List.Id)
 $ClientContext.Load($WorkflowAssociations)
$ClientContext.ExecuteQuery()

还想了解如何将审批者名称传递给以下方法:

 $WorkflowInstanceService.StartWorkflowOnListItem($WorkflowAssociations[0],  $ListItems[$j].Id, $Dict)

0 个答案:

没有答案