Thomas Ellermanns view on System Center

This blog will discuss features, functions and views on Operations Manager and Service Manager

Cancel pending activities in a failed Service Request

Cancel pending activities in a failed Service Request

  • Comments 4
  • Likes

Travis Wright has a couple of years ago, written a blog on how to cancel pending activities in a failed Change Request:

I often get the request to make a similar solution for Service Requests and thought it was about time to document it. 

Open the Authoring console and create a new Management Pack.

Right-click on Workflows and select Create

Give the workflow a name:


Choose to trigger the workflow based on a condition occurring in the database:

And subscribe to Service Requests being updated where the criteria is Status BEFORE Not Equal to Failed and Status AFTER Equal to Failed.



 Then finish out the wizard.

That will drop you into the workflow designer. Drag a single PowerShell script activity from the
toolbox onto the workflow designer and give it a name:



Then click thebutton on the Script Body attribute in the Details pane and insert the Powershell script.



Here is the script so you can copy it if you want to:

import-module smlets
$InProgress = Get-SCSMEnumeration -Name ActivityStatusEnum.Ready

$Cancelled = Get-SCSMEnumeration -Name ActivityStatusEnum.Cancelled

$ServiceRequest = Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.ServiceRequest$) -Filter "Id -eq $ServiceRequestID"

$ChildActivities = (Get-SCSMRelationshipObject -BySource $ServiceRequest |?{$_.RelationshipID -eq "2da498be-0485-b2b2-d520-6ebd1698e61b"})

$ChildActivities | %{$Activity = Get-SCSMObject -ID $_.TargetObject.Id; if($Activity.Status -eq $InProgress){$Activity | Set-SCSMObject -Property Status -Value $Cancelled}}


Then you need to bind the ID of the Service request that triggers the workflow to the $ServiceRequestID variable. To do this switch to the Script Properties tab. Enter ‘ServiceRequestID’
in the Name column (so that it exactly matches the name of the $ServiceRequestID variable in the PowerShell script) and then click the … button and choose the ID property (not ID (Internal)).





Now save the management pack. That will produce a .dll file that contains the workflow code.

To deploy the slution:

Import the MP into SCSM and Copy the .dll to C:\Program Files\Microsoft System Center 2012\Service Manager  directory on the SCSM management server where the workflows are running.

First, here’s an SR waiting for an approval:


Let’s play along and deny the request. Normally the SR would fail and the remaining activites will stay in Pending mode.


Now, with the new Workflow in place, the remaining activites are changed from Pending to Cancelled.


So like with the CR activities, you can actually restart the Review Activity and all the Manual activites
will go back to pending, awaiting the RA to be approved.


Attached is the MP and DLL I've created as I wrote this blog.

Attachment: Cancel
  • Doesn't work for me. I have checked the code in PS - works fine. Workflow result is succeeded but no changes to Activity

  • Works fine. Sorry: i have used Travis' post and replaced CRs with SRs like Thomas did but i could have made a mistake somewhere. Recreated the MP and it works fine. Thanks Thomas

  • How would we go back and cancel all of the pending activities from all failed SRs? This workflow is great for ones that are create after I implemented the workflow. However I have a mess of pending activities that are cluttering up our views.

  • Hello, is this a SCSM 2010 or 2012 solution please? I have imported the management pack and placed the dll in C:\Program Files\Microsoft System Centre 2012\Service Manger, but get an error on the workflow -2130771918 to the effect that the file could not be found, I assume it is referring to the dll, but not 100% sure. Any thoughts please?

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment