Cancelling Pending Activities When a Change Request Fails
Published Feb 15 2019 06:14 AM 504 Views
First published on TECHNET on May 03, 2011

Here is a common complaint that I hear from customers….  When an activity fails in a change request such as manual activity status changing to failed or when a review activity is rejected the change request status as a whole will change to Failed.  Here in this series of screenshots I’ll demonstrate the sequence of events.

First, this is a change request going through its normal cycle.  The MA255 manual activity is now the currently In Progress activity.

Now, let’s say that the person it is assigned to marks that activity as failed….

A system workflow provided out of the box will kick in and mark the parent change request as failed to.

Here’s where the problem comes in.  The manual activities are still in the Pending status.  Some people might argue that is appropriate given the situation.  Other people think that the status of these activities should be something more like Cancelled.  Fair enough.  In this blog post, I’ll show you how to do that automatically using a workflow and a PowerShell script that uses SMLets .

The approach to this blog post is similar to the PowerShell script I showed in this other blog post so you might want to check that out for background information:

http://blogs.technet.com/b/servicemanager/archive/2011/04/21/using-smlets-beta-3-post-2-using-g...

First, we need to open the Authoring Tool and create a new management pack.  Then we right click on the Workflows node in the Management Pack Explorer and choose to create a new Workflow as follows….

Give the workflow a name:

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

And subscribe to change 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 the … button on the Script Body attribute in the Details pane

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
$ChangeRequest = Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.ChangeRequest$) -Filter "Id -eq $ChangeRequestID"
$ChildActivities = (Get-SCSMRelationshipObject -BySource $ChangeRequest | ?{$_.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}}

And a screenshot from my script editor that is a little easier to read:

Then you need to bind the ID of the change request that triggers the workflow to the $ChangeRequestID variable.  To do this switch to the Script Properties tab.  Enter ‘ChangeRequestID’ in the Name column (so that it exactly matches the name of the $ChangeRequestID 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 solution:

Import the MP into SCSM.

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

Now, this is the experience.  When a CR status changes to failed the child activities that are currently Pending will have their status change to Canceled.

If you want to redo an activity just click the ‘Return to Activity’ task in the task pane when you have the CR selected:

Then choose the activity that you want to return to.

Then save the CR.  A workflow will kick in and make the remaining activities after that activity have a status of ‘Pending’ again:

I have made this solution available on the TechNet Gallery here:

http://gallery.technet.microsoft.com/Cancel-Pending-Change-7b0ae310

Version history
Last update:
‎Mar 11 2019 08:44 AM
Updated by: