pfizer viagra

Change Request and Incident Data passed to Activities

I don’t know about you guys but my people were giving me hell over the fact that you could not get parent data into activity email notifications. This was a huge problem for our implementation. Below is how I solved it.

In a nutshell I created a custom workflow activity and then bound it to whenever a change request or incident is created. The workflow activity then copies fields into an extension class for review and manual activities. Let’s start with the management pack that extends review and manual activities

<ClassTypes>
        <ClassType ID="Interclick.ManualActivity.ExtensionClass" Accessibility="Public" Abstract="false" Base="CoreActivity!System.WorkItem.Activity.ManualActivity" Hosted="false" Singleton="false" Extension="true">
          <Property ID="ParentTitle" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
          <Property ID="ParentDescription" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
          <Property ID="ParentArea" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
          <Property ID="ParentImpact" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
          <Property ID="ParentPriority" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
          <Property ID="ParentRisk" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
          <Property ID="ParentScheduledStart" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
          <Property ID="ParentScheduledEnd" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
        </ClassType>

        <ClassType ID="Interclick.ReviewActivity.ExtensionClass" Accessibility="Public" Abstract="false" Base="CoreActivity!System.WorkItem.Activity.ReviewActivity" Hosted="false" Singleton="false" Extension="true">
          <Property ID="ParentTitle" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
          <Property ID="ParentDescription" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
          <Property ID="ParentArea" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
          <Property ID="ParentImpact" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
          <Property ID="ParentPriority" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
          <Property ID="ParentRisk" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
          <Property ID="ParentScheduledStart" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
          <Property ID="ParentScheduledEnd" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false"  />
        </ClassType>
      </ClassTypes>

You can modify this to support the fields you need for your use cases. I created as many as I could so wouldn’t have to keep changing it.

Now create a Windows workflow activity library application in Visual Studio. Reference the following assemblies

  • System.Drawing – if you don’t know where that is you need another job.
  • Microsoft.EnterpriseManagement.Core – this can be found in the “SDK Binaries” directory on the SCSM server
  • Microsoft.ServiceManager.WorkflowAuthoring.ActivityLibrary – this can be found in the SCSM authoring “PackagesToLoad” directory
  • System.ServiceManager.Facade – you can get this on CodePlex by downloading the current source code and compiling

Below is the code that I used in my workflow activity, I was under a very tight deadline so no comments from the peanut gallery. I will clean it up later.

 protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            SCSMServer.SetCurrentManagementGroup("localhost");
            var changeRequestProjection = SCSMChangeRequest.GetChangeRequest(WorkItemId);
            
            foreach (var activityProjection in changeRequestProjection)
            {
                var activity = activityProjection.Value.Object;
                if (activity[null, "Id"] == null) break;

                activity[null, "ParentId"].Value = (changeRequestProjection.Object[null, "Id"].Value != null)
                                                         ? changeRequestProjection.Object[null, "Id"].Value.ToString
                                                               ()
                                                         : null;

                activity[null, "ParentTitle"].Value = (changeRequestProjection.Object[null, "Title"].Value != null)
                                                           ? changeRequestProjection.Object[null, "Title"].Value.ToString
                                                                 ()
                                                           : null;

                activity[null, "ParentDescription"].Value =
                    (changeRequestProjection.Object[null, "Description"].Value != null)
                        ? changeRequestProjection.Object[null, "Description"].Value.ToString()
                        : null;

                activity[null, "ParentArea"].Value = (changeRequestProjection.Object[null, "Area"].Value != null) ? ((ManagementPackEnumeration)changeRequestProjection.Object[null, "Area"].Value).DisplayName : null;

                activity[null, "ParentImpact"].Value = (changeRequestProjection.Object[null, "Impact"].Value != null) ? ((ManagementPackEnumeration)changeRequestProjection.Object[null, "Impact"].Value).DisplayName : null;

                activity[null, "ParentPriority"].Value = (changeRequestProjection.Object[null, "Priority"].Value != null) ? ((ManagementPackEnumeration)changeRequestProjection.Object[null, "Priority"].Value).DisplayName : null;

                activity[null, "ParentRisk"].Value = (changeRequestProjection.Object[null, "Risk"].Value != null) ? ((ManagementPackEnumeration)changeRequestProjection.Object[null, "Risk"].Value).DisplayName : null;

                if ((changeRequestProjection.Object[null, "ScheduledStartDate"].Value != null))
                {
                    var value = changeRequestProjection.Object[null, "ScheduledStartDate"].Value.ToString();
                    var date = DateTime.Parse(value);
                    activity[null, "ParentScheduledStart"].Value = date.ToString("g");
                }

                if ((changeRequestProjection.Object[null, "ScheduledEndDate"].Value != null))
                {
                    var value = changeRequestProjection.Object[null, "ScheduledEndDate"].Value.ToString();
                    var date = DateTime.Parse(value);
                    activity[null, "ParentScheduledEnd"].Value = date.ToString("g");
                }
                changeRequestProjection.Overwrite();               
               
            }

          return ActivityExecutionStatus.Closed;

        }

Please note “if (activity[null, "Id"] == null) break;” for some reason at least on my box the foreach loop does not stop on the last activity and so without this statement it throws null reference exceptions.

To get all that in a workflow see this link. On a side note I would use the management pack that you used to extend the activity types.

In the System Center Service Manager (SCSM) authoring tool you will need to create two workflows using your custom activity. One workflow is for when incident is created and the other for when a change request is created assuming you want to do this on both objects.

So import your management pack and create a change request or incident save it and when you go back to the activities, open one of them and you should see the following at least this is what I see

You can then use these fields in manual and review activity notifications. I am working on a solution to the problem of adding activities once a change request or incident has been created. Since the parent ID is stored in a sibling activity I should be able to figure it out. Same Bat Time Same Bat Channel.

As Travis said “Sweet Hotness”.

Comments

  1. Sandro Cocco says:

    Hi,
    I don’t know how to implement the System.ServiceManager.Facade.
    I haven’t found any documentation on how to do it.
    Can you please tell me how I should proceed.
    Thank you

    Sandro Cocco

  2. Rob says:

    Hello G – Before I get too excited I just wanted to understand this a bit more. Your saying by using the method above I can view the change request and incident info in a manual and review activity? Does that also work with related work items? Also send e-mails with that info as well?

    Ok the scenario I am encountering is that I am trying to e-mail(using review activity class) activity ID, change request ID, and the related items ID as well and from what I’ve read and asked online I cannot since Service Manager out of the box cannot make that many hops. So basically I can only provide the reviewer the change request ID and activity ID which is a pain. So your example would be able to assist? I just want to make sure before I jump out of my shoes.
    Thanks,

    Rob

  3. Rob says:

    Thanks Gary…last question. Is what you have up there compatible with Service Manager 2012? Just need to make sure before I implement anything. (No test enviroment)

Speak Your Mind

*