ค้นหาเว็บไซต์

SharePoint Online: แสดงงานทั้งหมดที่กำหนดให้กับกลุ่มของฉัน


ข้อกำหนด: ในรายการงาน SharePoint Online รับงานทั้งหมดที่กำหนดให้กับผู้ใช้ที่เข้าสู่ระบบและกลุ่มของผู้ใช้

หากคุณต้องการกรองรายการงานที่กำหนดให้กับผู้ใช้ปัจจุบัน คุณสามารถตั้งค่าตัวกรอง [ฉัน] ในการตั้งค่ามุมมองได้ แต่หากมีการกำหนดรายการงานให้กับกลุ่มและผู้ใช้ที่เข้าสู่ระบบเป็นสมาชิกของกลุ่มนั้น เราจะแสดงได้อย่างไร ไม่มีวิธีใดที่จะตั้งค่าตัวกรองดังกล่าวจากส่วนต่อประสานผู้ใช้บนเว็บ ดังนั้น มาสร้างมุมมองรายการใหม่โดยใช้ PowerShell เพื่อกรองรายการงานที่กำหนดให้กับผู้ใช้ปัจจุบันและกลุ่มของผู้ใช้ปัจจุบันใน SharePoint Online

รับงานทั้งหมดที่กำหนดให้กับผู้ใช้ปัจจุบันและกลุ่มผู้ใช้ปัจจุบัน

แม้ว่าคุณจะสามารถแก้ไขแบบสอบถามด้วยตัวออกแบบ SharePoint ได้ แต่เรามาสร้างมุมมองรายการใหม่โดยใช้ PowerShell ซึ่งจะกรองงานทั้งหมดที่กำหนดให้กับผู้ใช้ปัจจุบันและกลุ่มของผู้ใช้ปัจจุบัน


#Load SharePoint CSOM Assemblies
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"

#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
}

และมุมมองรายการจะแสดงงานที่มอบหมายให้กับกลุ่มของฉันและฉัน

มุมมองนี้ช่วยให้คุณเห็นงานทั้งหมดที่มอบหมายให้กับกลุ่มของคุณได้ในที่เดียว

บทความที่เกี่ยวข้อง