Cancelling Pending Activities When a Change Request Fails

Cancelling Pending Activities When a Change Request Fails

  • Comments 2
  • Likes

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.

image

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

image

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

image

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-get-scsmenumeration-get-scsmrelationshipobject-get-scsmrelationshipclass-to-automatically-resolve-incidents-when-all-child-activities-are-completed.aspx 

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:

image

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

image

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

image

image

image

Then finish out the wizard…

image

image

 

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:

image

Then click the … button on the Script Body attribute in the Details pane

image

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:

image

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)).

image

image

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.

image

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

image

Then choose the activity that you want to return to.

image

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

image

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

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

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • What if a Review Activity is Rejected- Failed? Does the rest of the activties get canceled too?

  • I am trying to use this for a rejected review activity but can not get it to run successfully. Can you please post changes required for this?