Home » scsm assign reviewer to review activity automatically

scsm assign reviewer to review activity automatically

by Nathan

(Hopefully) Useful Information on Microsoft System Center, Hyper-V and Cloud

Previous Post
Next Post
1
David Allen
SCSM – Assign Reviewer to Review Activity Automatically

Posted on July 13, 2015

 

Within Change Request templates in SCSM, it is common to add a Review Activity to the workflow to ensure the relevant people are aware of, and agree the change can taking place.  Placing a review activity at the beginning of a workflow (as in the image below) ensures that no other activities to actually do any work take place, and provides an audit trail for the change.

If you are lucky enough to work in an environment with a fixed set of approvers, this is an easy and straightforward approach, as the CR template can contain the review activity with the relevant approvers.  However, if you are in an environment where the approver can change based on the service or application being affected, for example, this process becomes a bit more long-winded for the person creating the CR, as they now have to know who the approver should be, manually open up the Review Activity in the workflow and add/amend approvers as required.

With Service Manager workflows though, this needn’t be an issue, because we can run a script at the time the CR is created that assesses the information provided and set the relecvant approvers.

The example I am providing below is a simple example of adding an approver to an associated review activity of a CR, where the user being set is the Assigned To user.  The PowerShell script in the workflow though could easily be updated to look at the affected CI field and then find the appropriate reviewer based on criteria you have in your environment.  This example will give you the framework to implement what you need in your environment.

Before beginning, the Service Manager Authoring Tool will be required, which can be downloaded here, http://www.microsoft.com/en-gb/download/details.aspx?id=40896.

Once the authoring tool has been installed, open it, and create a new blank management pack.  Update the filename of the new management pack to something more appropriate, and save.

 

After the management pack is saved, right click Workflows in the Management Pack Explorer and select Create.

This will launch the Create Workflow Wizard, and on the first General page, enter a useful Name and Description.

 

On the Trigger Condition page, select the “Run only when a database object meets specified conditions” radio button.

Next, define the trigger criteria by selecting the Change Request class, and setting the Change event to “When an object of the selected class is created”.

 

Confirm all the details are correct on the Summary page, and create the workflow, and then close the wizard.  This will then open the Sequential Workflow designer, where a PowerShell script can be added to perform the actions required.

 

From the Activities Toolbox, select the Windows PowerShell Script object, and drag it to inbetween the green start and red stop objects on the workflow.  Note, if you can’t see the Activities Toolbox, it can be opened from the View menu.  Once the activity is in place, it can be right-clicked and Details selected, to allow the script and properties to be added.

 

Click the ellipsis button in the Script Body field to open the configuration window for both the Script Body and Script Properties.  Here is where you can input a script to do whatever you need to do.  In this demo, I used the following script, which basically loads SMLets, gets the Assigned To user, and makes the same user a reviewer in the Review Activity which is part of the Change Request workflow.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

set-executionpolicy -executionPolicy ByPass
 
$a = (get-module|%{$_.name}) -join ” ”

if(!$a.Contains(“SMLets”)) {Import-Module SMLets -ErrorVariable err -Force}
 
$ReviewActivityClass = Get-SCSMClass -name ^System.WorkItem.Activity.ReviewActivity$
$WorkItemRelatesToWorkItemRelClass = Get-SCSMRelationshipClass -name ^System.WorkItemRelatesToWorkItem$
$WorkItemContainsActivityRelClass = Get-SCSMRelationshipClass -name ^System.WorkItemContainsActivity$
$WorkItemRelatesToUser = Get-SCSMRelationshipClass -name ^System.WorkItemAssignedToUser$
$RAHasReviewerRel = Get-SCSMRelationshipClass -Name ^System.ReviewActivityHasReviewer$
$ReviewerIsUserRel = Get-SCSMRelationshipClass System.ReviewerIsUser
 
$reviewerClass = get-scsmclass System.Reviewer
 
[System.Collections.ArrayList]$ReviewActivities = @()
 
$ChangeObj = Get-SCSMObject -Class (Get-SCSMClass -Name System.Workitem.ChangeRequest$) -Filter “Id -eq $CR_ID”
 
$OwnerUser = Get-SCSMRelatedObject -Relationship $WorkItemRelatesToUser -SMObject $ChangeObj
 
Function getReviewActivities {    
Param        
(        
[Parameter(Mandatory=$true)]$WorkItem        
)      

$ContainedActivities =  @()    
$ContainedActivities += Get-SCSMRelatedObject -Relationship $WorkItemContainsActivityRelClass -SMObject $WorkItem    

foreach ($Activity in $ContainedActivities)    
{      

if($Activity.ClassName -eq $ReviewActivityClass.Name)        
{
if($Activity.Title -eq “SO PM Initial Review”) {            
$Index = $ReviewActivities.Add($Activity)    
}    
}    
      
else        
{            
getReviewActivities -WorkItem $Activity        
}    
}}
 
getReviewActivities -WorkItem $ChangeObj
 
$ReviewActivity = $ReviewActivities[0]
$reviewerArgs = @{ ReviewerId = “Reviewer{0}” }
 
$Reviewer = $null
$Reviewer = new-scsmobject -class $ReviewerClass -PropertyHashtable $reviewerArgs -NoCommit
$RAStep1 = new-scsmrelationshipobject -NoCommit -relation $RAHasReviewerRel -source $ReviewActivity -target $Reviewer
$RAStep2 = new-scsmrelationshipobject -NoCommit -relation $ReviewerIsUserRel -source $Reviewer -target $OwnerUser
$RAStep1.Commit()
$RAStep2.Commit()

The script is placed in the Script Body field, and under Script Properties you can define data that is passed to the script.  In the script above I refer to $CR_ID which is a property that has it’s value defined in Script Properties.

 

After the script is in place, and properties configured, all the open windows can be OK’d or closed, and the management saved and sealed.  This will generate a number of files in the save location, but the only ones that are required to implement the solution into your Service Manager management group is the MP file and the DLL file. 

 

The DLL file needs to be placed in the Service Manager directory on your SCSM management server that runs workflows, typically the first management server that was installed, and the Microsoft Monitoring Agent will need restarting to pick up the new MP.  The MP file needs simply importing into the SCSM management group.

After all this is complete, and given a few minutes for the MP configuration to become active, any new change requests that are created will trigger the workflow to run, so in this scenario the CR Assigned To user will automatically be added as a reviewer in the Review Activity…  Success!

David

Share this:
Click to share on Twitter (Opens in new window)
Click to share on Facebook (Opens in new window)
Click to share on Google+ (Opens in new window)
Click to share on LinkedIn (Opens in new window)
Click to email this to a friend (Opens in new window)
Click to print (Opens in new window)
Click to share on Skype (Opens in new window)
Click to share on WhatsApp (Opens in new window)
Related

Tags: Management Pack, PowerShell, SCSM, Workflow

1 Comment
Chad Robertson April 14, 2016

Hey Great Post! I’m trying to get this to work in my environment but can’t seem to get it to add the apporver. I can see it runs without errors but not sure why the approver’s are not getting added. Any Advice?

Is this parameter for CR_ID ok? Activity=CR_Set_Approver, Path=windowsPowerShellScript1_CR_ID

Reply
Leave a Reply

Notify me of follow-up comments by email.

Notify me of new posts by email.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts
Azure Stack – Development Kit (Single Node)
Cireson Survey – Pre-Selecting The Satisfaction Slider
SCOM – Monitor SCSM Data Warehouse Jobs
SCOM – Updated Unsealed MP Backup Management Pack
Microsoft Azure – Securing Accounts With Access To The EA Portal
Archives
October 2017
September 2017
July 2017
November 2016
August 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
May 2015
February 2015
October 2014
September 2014
Categories
Azure
Azure Automation
Azure Stack
Cireson
Cluster
Configuration Manager
Data Protection Manager
Data Warehouse
Events
Hyper-V
Ignite
Management Packs
Microsoft Azure
OMS
Operations Manager
Orchestrator
Password Reset
Portal
PowerShell
SCU Europe
Service Manager
System Center
TechEd
Uncategorized
Updates
Visual Studio
Welcome
Windows Azure Pack
Windows Server 2012 R2
Windows Server 2016
Tags
Automation Azure Backup Barcelona Cireson Cloud Compliance Containers Dashboard Data Warehouse DCM DPM Events Grooming Hyper-V Ignite iPad Library Sharing Log Shipping Management Pack MPSync MVP Performance PowerShell Remediation Reporting RSAT SCCM SCOM SCSM SCU SQL SquaredUp System Center System Center 2016 Tape TechEd Technical Preview Update Rollup VMM WAP Window Server Windows Server Windows Server 2016 Workflow
Useful Sites
Aquilaweb Cloud Solutions
ClustrMap
MVP

© 2018 – Design by Frenchtastic.eu

Back to top