Public/Update-Task.ps1
function Update-Task { param( [string]$ChannelId, [string]$EntityId, [string]$GroupId, [string]$TeamId, [string]$Domain = "teams-stag.appvity.com", $TaskId, $TaskObject, [string]$Title, [string]$AssignedTo, [string]$Attachments, [string]$Body, [string]$Complete, [string]$CompletedDate, [string]$DueDate, [string]$Effort, [string]$Name, [string]$Owner, [string]$Priority, [string]$RelatedItems, [string]$StartDate, [string]$Status, [string]$ProjectId, $PhaseId, $BucketId, [string]$Cookie ) $validate = '' if(!$Domain){ $validate = $validate + ', Domain' } if(!$ChannelId){ $validate = $validate + ', ChannelId' } <# if(!$EntityId){ $validate = $validate + ', EntityId' } if(!$GroupId){ $validate = $validate + ', GroupId' } #> if(!$TeamId){ $validate = $validate + ', TeamId' } if(!$ProjectId){ $validate = $validate + ', ProjectId' } if(!$TaskId){ $validate = $validate + ', TaskId' } if($validate) { $validate = $validate.TrimStart(',').TrimStart() + ' is require' Write-Host $validate -F Red return } #cookie $cookie = $Cookie if(!$cookie){ $cookie = Get-GraphOauthCookie -BaseURL $Domain #Write-Host '-------------cookie------------------' #Write-Host $cookie } #get task detail $taskDetail = Get-TaskDetails -ChannelId $ChannelId -TeamId $TeamId -Domain $Domain -TaskId $TaskId -Cookie $Cookie if($taskDetail) { if(!$Title) {$Title = $taskDetail.name} if(!$AssignedTo) {$AssignedTo = $taskDetail.assignedTo} if(!$Attachments) {$Attachments = $taskDetail.attachments} if(!$Body) {$Body = $taskDetail.body} if(!$Bucket) {$Bucket = $taskDetail.bucket} if(!$Complete) {$Complete = $taskDetail.complete} if(!$CompletedDate) {$CompletedDate = $taskDetail.completedDate} if(!$DueDate) {$DueDate = $taskDetail.dueDate} if(!$Effort) {$Effort = $taskDetail.effort} if(!$Owner) {$Owner = $taskDetail.owner} if(!$Phase) {$Phase = $taskDetail.phase} if(!$Priority) {$Priority = $taskDetail.priority} if(!$RelatedItems) {$RelatedItems = $taskDetail.relatedItems} if(!$StartDate) {$StartDate = $taskDetail.startDate} if(!$Status) {$Status = $taskDetail.status} if(!$Source) {$Source = $taskDetail.source} } if($TaskObject) { #$object = $BodyObject | ConvertFrom-Json if($TaskObject.Title) {$Title = $TaskObject.Title} if($TaskObject.AssignedTo) {$AssignedTo = $TaskObject.AssignedTo} if($TaskObject.Attachments) {$Attachments = $TaskObject.Attachments} if($TaskObject.Body) {$Body = $TaskObject.Body} if($TaskObject.Complete) {$Complete = $TaskObject.Complete} if($TaskObject.CompletedDate) {$CompletedDate = $TaskObject.CompletedDate} if($TaskObject.DueDate) {$DueDate = $TaskObject.DueDate} if($TaskObject.Effort) {$Effort = $TaskObject.Effort} if($TaskObject.Name) {$Name = $TaskObject.Name} if($TaskObject.Owner) {$Owner = $TaskObject.Owner} if($TaskObject.Priority) {$Priority = $TaskObject.Priority} if($TaskObject.RelatedItems) {$RelatedItems = $TaskObject.RelatedItems} if($TaskObject.StartDate) {$StartDate = $TaskObject.StartDate} if($TaskObject.Status) {$Status = $TaskObject.Status} if($TaskObject.BucketId) {$BucketId = $TaskObject.BucketId} if($TaskObject.PhaseId) {$PhaseId = $TaskObject.PhaseId} } <# #validation if(!$Title) { Write-Host "Title not found." -F red return } if(!$Source) { Write-Host "Source not found." -F red return } if(!$Priority) { Write-Host "Priority not found." -F red return } if(!$Status) { Write-Host "Status not found." -F red return } #> $phaseName = '' $bucketName = '' if($PhaseId) { $phases = Get-Phases -Domain $Domain -ChannelId $ChannelId -TeamId $TeamId -ProjectId $ProjectId -Cookie $cookie $phase = $phases | Where {$_.id -eq $PhaseId} | Select displayName $phaseName = $phase.displayName if($BucketId) { $buckets = Get-Buckets -Domain $Domain -ChannelId $ChannelId -TeamId $TeamId -ProjectId $ProjectId -PhaseId $PhaseId -Cookie $cookie $bucket = $buckets | Where {$_.id -eq $BucketId} | Select displayName $bucketName = $bucket.displayName } } $Arr = @{ name = $Title status = $Status body = $Body source = $Source priority = $Priority startDate = $StartDate dueDate = $DueDate attachments = $Attachments bucket = $BucketId bucketName = $bucketName complete = $Complete completedDate = $CompletedDate effort = $Effort owner = $Owner phase = $PhaseId phaseName = $phaseName projectId = $ProjectId relatedItems = @() assignedTo = @() } | ConvertTo-Json #header $hd = New-Object 'System.Collections.Generic.Dictionary[String,String]' $hd.Add("x-appvity-channelId",$ChannelId) $hd.Add("x-appvity-entityId",$EntityId) $hd.Add("x-appvity-groupId",$GroupId) $hd.Add("x-appvity-teamid",$TeamId) $hd.Add("Content-Type","application/json") #session $session = New-Object Microsoft.PowerShell.Commands.WebRequestSession $ck = New-Object System.Net.Cookie $ck.Name = "graphNodeCookie" $ck.Value = $cookie $ck.Path = "/" $ck.Domain = $Domain $session.Cookies.Add($ck); $Url = 'https://' + $Domain.TrimEnd('/') + '/odata/tasks(' + $TaskId + ')' $Params = @{ Uri = $Url Method = 'PATCH' Headers = $hd Body = $Arr } try { Invoke-WebRequest @Params -WebSession $session } catch{ Write-Error $_.Exception.Message } } |