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 the 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 a member of that group, how do we show them? Well, there is no way to set such a filter from the web user interface. So, let’s create a new list view using PowerShell to filter task list items assigned to the 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, let’s create a new list view using PowerShell which filters all tasks assigned to the 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

Salaudeen Rajack

Information Technology Professional with Two decades of SharePoint Experience.

One thought on “SharePoint Online: Show All Tasks Assigned to My Group

  • September 4, 2020 at 7:12 AM

    This is very useful post to me and my team. I was not about this view approach. Saved lot of coding effort and time for me and my team.

    Thanks – Jigar

    Reply

Leave a Reply