SharePoint Online: Show All Tasks Assigned to My Group

Requirement: In SharePoint Online Task List, Get All Tasks Assigned to the Logged in User and User's Groups.

If you want to filter task list items assigned to current user, you can simply set the [Me] filter in view settings. But If a Task item assigned to a group and the logged-in user is member of that group, how do we show them? Well, there is no way to set such filter from web user interface. So, lets create a new list view using PowerShell to filter task list items assigned to current user and current user's groups in SharePoint Online.
sharepoint online show tasks assigned to my group

Get All Tasks Assigned to Current User and Current User's Groups
Although you can edit the query with SharePoint designer, Lets create a new list view using PowerShell which filters all tasks assigned to current user and current user's groups.
#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
}
and the list view shows tasks assigned to me and my group
sharepoint online view task assigned to my group

SharePoint Online: Show All Tasks Assigned to My Group SharePoint Online: Show All Tasks Assigned to My Group Reviewed by Salaudeen Rajack on August 17, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.