søndag den 10. november 2013

Relate CI to Multiple Activities in a Service Request

Scenario: You have a Request Offering on the portal in which the user will select a CI. The CI is attached to the Service Request as a Related Item.
You also need that CI to be available to some of the activities. The scenario is close to mapping prompt outputs from a Request Offering to fields in multiple Work Items. Maybe the user entered and ID number of sorts which is relevant information for more than one activity in a Service Request.

First create a Service Request Template and add a few activities similarly to what has been done below
Add a Manual Activity at the end of the flow with the title "Dummy".

We need 4 runbooks. one that monitors new Service Requests, one that will get all the Manual Activities in that Service Request, one that creates a relation in each Manual Activity to the CI. And the last runbook ties them all together.

The monitoring runbook is just as one would expect.

Relate CI to Multiple Activities in a Service Request
In this example I get all related "Windows Computers" and feed them to "Relate CI to MA".
"Relate CI to MA" - This runbook will be called as many times as there are Manual Activities in the Service Request.
The magic happens in this runbook:
Get Manual Activity IDs in SR
Get Related MAs
Get 'Dummy' MA

Delete MA Relation - Removes the Dummy Activity from the Service Request
The Script looks like this:

Set-ExecutionPolicy Unrestricted -Scope Process -Force

Import-Module -Name 'SMLets'

$S = "MA{ID from "Get SR"}".Replace("SR","");
$E = "{ID from "Get 'Dummy' MA"}";

$MAIDs = Get-SCSMObject -Class (Get-SCSMClass -Name "System.WorkItem.Activity.ManualActivity$") -Filter "DisplayName -gt `"$S`" -and DisplayName -lt `"$E`"" | Select -ExpandProperty Id;

This is what we needed the 'dummy' for. Altenately one could cycle through all the Manual Activites and pick the one with the highest ID. The Run .NET Script activity must publish the $MAIDs variable.
Return Data
And finally we relate the CI to the MA - Under properties for this runbook in the "Concurrency" tab, enter a number greater than 1 for "Maximum number of simultaneous jobs". As many as you expect there will be of Manual Activities in a Service Request without overloading your runbook server. 5-10 is a good number (depending on your hardware setup).
Testing: Start the monitoring runbook and create an instance of the template from the beginning of this tutorial and add a "Windows Computer" in the "Related Items" tab of the Service Request - or whatever class of CI your runbook supports.

Extending: As you may only want to relate CIs in specific Service Requests, or different types of CIs for each Service Request you will have to add some logic to the "Relate CI to Multiple Activities in a Service Request"-runbook.

Alternatives: Instead of using a monitor you could add a runbook-activity as the first activity in the Service Request.

Ingen kommentarer:

Send en kommentar

Bemærk! Kun medlemmer af denne blog kan sende kommentarer.

Søg i denne blog