【发布时间】:2018-05-01 16:06:14
【问题描述】:
我正在尝试将审批工作流附加到我的 SharePoint 库,但每次我得到一个 '值不能为空',
但我不知道哪里出错了,
下面是我正在尝试的 PowerShell 代码
我是否缺少任何参数来给出值?
其他功能只是检查列表是否存在,如果不存在则创建它, 同样在创建列表时,我无法在方法 createListByTemplate() 中找到列表模板 f0r Task (2010)
谢谢 帕鲁
function TryGetList($spoCtx,$listName)
{
$web = $spoCtx.Web
$lists = $web.Lists
$spoCtx.Load($web)
$spoCtx.Load($lists)
$spoCtx.ExecuteQuery()
$listExist = $web.Lists | where{$_.Title -eq $listName}
if($listExist)
{
return $true
}
else
{
return $false
}
}
function CreateListbyTemplate($spoCtx,$listName,$listTemplate,$listDescription)
{
try
{
$spoWeb=$spoCtx.Web
$spoListCreationInformation=New-Object Microsoft.SharePoint.Client.ListCreationInformation
$spoListCreationInformation.Title=$listName
$spoListCreationInformation.Description = $listDescription
$spoCtx.Load($web.ListTemplates)
$spoCtx.ExecuteQuery()
#$spoListCreationInformation.TemplateType=[int][Microsoft.SharePoint.Client.ListTemplatetype]::GenericList
#$spoList=$spoWeb.Lists.Add($spoListCreationInformation)
$spoListCreationInformation.ListTemplate = $web.ListTemplates | where {$_.InternalName -match $listTemplate }
$spoWeb.Lists.Add($spoListCreationInformation)
$spoCtx.ExecuteQuery()
return $listName
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
Write-Host "List "$listName" created !!" -ForegroundColor Green
$spoCtx.Dispose()
}
catch [Exception]
{
Write-Host -ForegroundColor Red "An Error Occured"
$_.Exception.Message
}
}
# $spoCtx has current context
function attachApprovalWorkflow($spoCtx)
{
try
{
$SuccessLogs=$records.LogImportSuccess + (get-date -f yyyy-MM-dd_hh_mm_ss).ToString()+".csv"
$FailureLogs=$records.LogImportFailure + (get-date -f yyyy-MM-dd_hh_mm_ss).ToString()+".csv"
Add-Content $SuccessLogs “ID, Status”;
Add-Content $FailureLogs “ID,Message”;
[Microsoft.SharePoint.Client.Web]$web = $spoCtx.Web
try
{
$liststoignore = @("Workflow History", "Workflow Tasks", "Master Page Gallery", "Composed Looks", "MicroFeed", "Site Assets", "Site Pages","Documents", "appdata", "appfiles", "Converted Forms", "Form Templates", "List Template Gallery", "Solution Gallery", "Style Library", "TaxonomyHiddenList", "User Information List", "Web Part Gallery", "Theme Gallery")
[Microsoft.SharePoint.Client.ListCollection] $lstcoll = $spoCtx.Web.Lists;
$spoCtx.Load($lstcoll);
$spoCtx.ExecuteQuery()
foreach($listsName in $lstcoll)
{
if ($listsName.BaseTemplate -eq 101 -and !$liststoignore.Contains($listsName.Title))
{
[Microsoft.SharePoint.Client.List]$list = $web.Lists.GetByTitle($listsName.Title)
$spoCtx.load($list)
$spoCtx.ExecuteQuery();
##################
$tasklist = TryGetList $spoCtx "Workflow Tasks"
if ($tasklist -eq $false)
{
$tasklist = CreateListbyTemplate $spoCtx "Workflow Tasks" "Tasks (2010)" "Workflow Tasks" + " list"
}
else
{[Microsoft.SharePoint.Client.List]$tasklist1 = $web.Lists.GetByTitle("Workflow Tasks")
$spoCtx.load($tasklist1)
$spoCtx.ExecuteQuery()
}
$historylist = TryGetList $spoCtx "Workflow History"
if ($historylist -eq $false)
{
$historylist = CreateListbyTemplate $spoCtx "Workflow History" "Workflow History" "Workflow History" + " list"
}
else
{
[Microsoft.SharePoint.Client.List]$historylist1 = $web.Lists.GetByTitle("Workflow History")
$spoCtx.load($historylist1)
$spoCtx.ExecuteQuery()
}
###################
$workflowName = $listsName.Title + " Workflow"
$wfApprovalWFTemplate = $web.WorkflowTemplates.GetByName("Approval - SharePoint 2010")
$spoCtx.Load($wfApprovalWFTemplate)
$spoCtx.ExecuteQuery()
#Create a Workflow Association info
$wfassociationInfo = New-Object Microsoft.SharePoint.Client.Workflow.WorkflowAssociationCreationInformation;
$wfassociationInfo.ContentTypeAssociationTaskListName = $tasklist1
$wfassociationInfo.ContentTypeAssociationHistoryListName = $historylist1
$wfassociationInfo.Template = $wfApprovalWFTemplate
$wfassociationInfo.Name = $workflowName
$wfassociationInfo.TaskList =$web.Lists.GetByTitle("Workflow Tasks")
$wfassociationInfo.HistoryList = $web.Lists.GetByTitle("Workflow History")
#Associate to the Document Library where you want the approval WF to be added .
Write-Host "Create a new Workflow Associationg with the Neccesary information."
$wf = $list.WorkflowAssociations.Add($wfassociationInfo)
$wf.AutoStartChange = $false
$wf.AutoStartCreate = $false
$wf.AllowManual = $true
$wf.Update();
$spoCtx.ExecuteQuery()
Write-Host -ForegroundColor Yellow "Workflow enabled on " $list.Title
Add-Content $SuccessLogs $list.Title
}
}
}
catch [Exception]
{
Write-Host -ForegroundColor Red "An Error Occured" $list.Title
$_.Exception.Message
Add-Content $FailureLogs $listsName +","+$_.Exception.Message
}
}
catch [Exception]
{
Write-Host -ForegroundColor Red "An Error Occured"
$_.Exception.Message + $list.Title
}
}
【问题讨论】:
-
哪一行报错了?
-
$wf = $list.WorkflowAssociations.Add($wfassociationInfo) 这一行,同时将工作流附加到列表中
标签: powershell sharepoint sharepoint-online csom