Creating SCSM Work Items from Template in Orchestrator (with Prefixes!)

One of the most common complaints I’ve heard when creating work items from a template in Orchestrator is the lack of prefixes on the activities. This same problem exists when using SMLets to create a work item from a template. Since the Id is a key value there is no way to go back after it has been created and add the prefix. However, using Orchestrator, the SDK, and a little C#, you can work around this problem.

To do this you need to copy the Service Manager SDK binaries to your runbook server, then use the Run .Net Script activity in Orchestrator. In this example I will be creating a Service Request, but you could easily update the code for other classes. Also, due to the limitations of the Run .Net Script activity this only works for top level activities. So if you have parallel or sequential activities this will not update the activities inside of it. Although I am working on a work around for this, and will post the solution as soon as it is ready.

Update: I have released a stand alone executable that you can use to get around the problem of parallel and sequential activities. Click here for more details.

First start by copying the SDK Binaries folder from the Service Manager management server to your runbook server. If you have installed the Service Manager console, or SMLets on your runbook server, these may already be on your server. Once you have these on your runbook server you are ready to create your runbook.

In the code example here I am creating a Service Request by passing the template’s Guid to the Run .Net Script activity. This little bit of code will create the Service Request, then set the prefixes, and save. It will then output the SC Object Guid of the Service Request it created, so that you can use the standard SCSM integration pack activities to make any other required changes to the request.

  1. Start by adding a new Run .Net Script activity to you runbook.
  2. Then set the Type to C#.
  3. Next on the Advanced tab add the following Namespaces.
  4. Then add the following references
    C:\Microsoft.EnterpriseManagement.Core.dll (your path may be different based on where you copied the SDK binaries to)
  5. On the Published Data tab, create a variable named strSRGuid
  6. Now you are ready to enter the C# code. On the details tab paste in the code below.
  7. You will need to provide the Guid of the template you want to use and the name of your Service Manager management server. On lines 1 and 2. Other than that you can leave the code as is.

The easiest way to get the Guid of the template is to use the Get-SCSMObjectTemplate PowerShell cmdlet. You could easily put this in another Run .Net Script prior to this one and pass in the Guid that way.

Leave a Reply