I needed to create a workflow that will cancel pending Activities for Failed and Cancelled SR. I found Travis's CR technet and was able to reproduce it for SR. I also needed to include the Completed Date value in order to get the SLA to stop on a cancelled and failed SR.
Here is my script:
$InProgress = Get-SCSMEnumeration -Name ActivityStatusEnum.Ready $Failed = Get-SCSMEnumeration -Name ActivityStatusEnum.Failed $Cancelled = Get-SCSMEnumeration -Name ActivityStatusEnum.Cancelled $SRCancelled = Get-SCSMEnumeration ServiceRequestStatusEnum$ $SRStatusCancelled = Get-SCSMChildEnumeration -Enumeration $SRCancelled |?{$_.DisplayName -eq "Cancelled"} $Date = Get-Date -Format g $SRequest = Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.ServiceRequest$) -Filter "Id -eq $ServiceRequestID" $SRImpList = Get-SCSMEnumeration ServiceRequestImplementationResultsEnum$ $SRImpStatusFailed = Get-SCSMChildEnumeration -Enumeration $SRImpList |?{$_.DisplayName -eq "Failed"} $SRImpStatusCancelled = Get-SCSMChildEnumeration -Enumeration $SRImpList |?{$_.DisplayName -eq "Cancelled"} $ChildActivities = (Get-SCSMRelationshipObject -BySource $SRequest | ?{$_.RelationshipID -eq "2da498be-0485-b2b2-d520-6ebd1698e61b"}) $SRequest| Set-SCSMObject -Property CompletedDate -Value $Date $ChildActivities | %{$Activity = Get-SCSMObject -ID $_.TargetObject.Id; if($Activity.Status -eq $InProgress){$Activity | Set-SCSMObject -Property Status -Value $Cancelled}} If($SRequest.Status -eq $SRStatusCancelled){$SRequest |Set-SCSMObject -Property ImplementationResults -Value $SRImpStatusCancelled} else {$SRequest |Set-SCSMObject -Property ImplementationResults -Value $SRImpStatusFailed}
It works but it seems that when the SR contains multiple activities, the Completed Date is updated multiple times every minute or so and never stops till i restart the HealthService.
I tried moving the line
$SRequest| Set-SCSMObject -Property CompletedDate -Value $Date
in different places in the script but its seems to be always the same result.
What is the problem?Also, is it normal that the time of the Completed date is 5h behind EST time?
Would it be possible to retrieve & set the SLA Cancel value to "yes" instead of having to update the Completed date? I know that this is set to Cancel = "yes" when your SLO is updated (ie change priority).