top of page
  • Glen (Xapity)

PowerShell for SCSM: Copy Approvers to Child Review Activities

This post shows the PowerShell script that was described in the Activity Work Item Tags blog.

Analysts do not like going into activities to fill out data. They would just rather fill out the parent work item and have it automatically copy to the children activities. This is good in theory, but you soon run into the problem of what action do I take on which activity - i.e. how do I tell them apart?

Activity Tags are a way of providing some data about the activity that helps decide what action you want to take on a particular activity. When using PowerShell it can be complicated tom work out what the purpose of the activity is and relying on keywords in the Title and Description can be difficult as analysts aren't aware of their importance.

So we added a list field to the Review Activity (ReviewActivityTag) and populated the list with the values:

• Change - Business Approver • Change - Technical Approver • Release - Business Approver • Release - Technical Approver

We then extended the Change and the Release classes to add two Relationships:

Change Relationships • ChangeBusinessApprover • ChangeTechnicalApprover

Release Relationships • ReleaseBusinessApprover • ReleaseTechnicalApprover

Extended the Change and Release forms to add User Pickers so that Analysts can fill out the correct information.

SCSM PowerShell - Copy Approvers

Now create a template, in this example a Minor Change request and build up a workflow using Xapity PowerShell Activities. In this case we will use one to copy the approvers and one to copy the description:

User Xapity PowerShell Activity to copy Approvers and Description in a workflow

The copy description script is documented in this blog: PowerShell Scripting: Copy Parent Description to Children Activities

High Level Explanation of Copy Approvers Script

The script is based on a script David Allen posted on Aquilaweb Blog:

Step 1 : Start with importing SMLets Smlets can be downloaded from here:

Step 2 : Set the Review Activity Class and Relationships In this script we know we are going to be setting Review Activity Approvers. So we need to get the general class for the Review Activity and for Reviewer. Then we need to get the Relationship class for the "Review Activity has Reviewer" and then for the "Reviewer".

Note: To get to the Approver on a Review Activity we are actually going down two levels of relationships. The first is does the Review Activity have a reviewer set and then a relationship to find out who that reviewer is.

Step 3 : Determine if the Parent is a CR or RR and then set more Relationship classes This script is designed to work with CR and RR. The IF statement determines which we are working with and then allows us to get the specific relationship classes for that work item (using the relationships defined above).

Step 4 : Get the SCSM Objects This is where we get the actual SCSM objects that we will be working with - the parent CR or RR and the data entered by the Analysts for Business Approver and Technical Approver.

The $ParentID variable is a built-in variable from the Xapity PowerShell Activity.

Step 5 : Optional: Write out data gathered This is an optional step and was useful when testing to see that the correct data was being collected.

Step 6 : Find all Review Activities on the Parent Work Item

Step 7 : Loop through the Activities

Step 8 : Check the Activity for the Activity Tag Now that we have the Activity properties we can do a check against the display name of the ReviewActivityTag. If you drop the display name you will need to match against the Enum. This would be a better option if you edit the list in the future. But for this example it makes it more readable to use display name.

Step 9 : Set the Approver on the Review Activity Now we finally set the appropriate approver on the Review Activity. This could also be implemented as a function, but again to make it more straight forward I have repeated the code block in each IF statement.

First get the SCSM RA Object using the current Activity ID. Then define the options for the Reviewer - set $true if you want to enable the Must Vote or Veto options.

As the Reviewer is a double hop relationship we need to set both relationships together and then commit them. Again thanks to David Allen for this bit of the code.

Final Note There is no error checking logic in the script, so if it is run twice, it will populate the Reviewers twice. It does not check for null values for Approvers or if there are null value reviewers already entered on the RA. These would be useful enhancements in a production environment.

The Full Script

Download this script:


Xapity PowerShell Activities - Use PowerShell scripts in SCSM workflows

Xapity PowerShell Activity The Xapity PowerShell Activity is a new Activity for SCSM that enables PowerShell scripts to be run in SCSM workflows. Automate more of your processes directly in SCSM. Scripts are stored and updated from a central script repository. The scripts execution output can be viewed and if a failure occurs, an Email Notification can be sent.

Xapity - Innovative Software for SCSM - Discover our Products

#PowerShell #Tips #PowerShellActivity #SCSM

253 views0 comments

Recent Posts

See All
bottom of page