当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] SharePoint Online:显示分配给我的组的所有任务

作者:精品下载站 日期:2024-12-14 14:41:38 浏览:13 分类:玩电脑

SharePoint Online:显示分配给我的组的所有任务


要求:在 SharePoint Online 任务列表中,获取分配给登录用户和用户组的所有任务。

如果您想过滤分配给当前用户的任务列表项,只需在视图设置中设置[我]过滤器即可。但是如果一个任务项被分配给一个组并且登录的用户是该组的成员,我们如何显示它们呢?嗯,无法从网络用户界面设置这样的过滤器。因此,让我们使用 PowerShell 创建一个新的列表视图,以筛选分配给 SharePoint Online 中当前用户和当前用户组的任务列表项。

[玩转系统] SharePoint Online:显示分配给我的组的所有任务

获取分配给当前用户和当前用户组的所有任务

虽然您可以使用 SharePoint 设计器编辑查询,但让我们使用 PowerShell 创建一个新的列表视图,该视图会筛选分配给当前用户和当前用户组的所有任务。


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Set parameter values
$SiteURL="https://crescent.sharepoint.com/"
$ListName ="Project Tasks"
$ViewName="My Group Tasks"

Try {
    #Setup Credentials to connect
    $Cred= Get-Credential
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
 
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Credentials
   
    #Get the List
    $List = $Ctx.Web.Lists.GetByTitle($ListName)
    $Ctx.Load($List)
    $Ctx.ExecuteQuery()
 
    #Check if the View exists in list already
    $ViewColl=$List.Views
    $Ctx.Load($ViewColl)
    $Ctx.ExecuteQuery()
    $NewView = $ViewColl | where { ($_.Title -eq $ViewName) }
    if($NewView -ne $NULL)  
    {
        Write-host "View '$ViewName' already exists in the List!" -f Yellow
    }
    else
    {
        #Define the CAML Query - Filter Assigned to: Current User or Current User's Group
        $ViewQuery = "@
                    <Where>
                        <Or>
                            <Eq>
                                <FieldRef Name='AssignedTo' />
                                    <Value Type='Integer'>
                                        <UserID />
                                    </Value>
                            </Eq>
                            <Membership Type='CurrentUserGroups'>
                                <FieldRef Name='AssignedTo' />
                            </Membership>
                        </Or>
                    </Where> "

        $ViewCreationInfo = New-Object Microsoft.SharePoint.Client.ViewCreationInformation
        $ViewCreationInfo.Title = $ViewName
        $ViewCreationInfo.Query = $ViewQuery
        $ViewCreationInfo.RowLimit = "100"
        $ViewCreationInfo.ViewFields = @("Title", "Status", "DueDate", "AssignedTo") 
 
        #Add List View
        $NewView =$List.Views.Add($ViewCreationInfo)
        $Ctx.ExecuteQuery()    
             
        Write-host "New View Created in the List Successfully!" -ForegroundColor Green  
    }
}
Catch {
    write-host -f Red "Error Adding View to List!" $_.Exception.Message
}

列表视图显示分配给我和我的小组的任务

[玩转系统] SharePoint Online:显示分配给我的组的所有任务

通过此视图,您可以在一个位置查看分配给您的组的所有任务。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯