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 |
"Relate CI to MA" - This runbook will be called as many times as there are Manual Activities in the Service Request. |
Get Manual Activity IDs in SR |
Get Related MAs |
Get 'Dummy' MA |
Delete MA Relation - Removes the Dummy Activity from the Service Request |
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 |
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.