Send a notification the Affected User of a Work Item when a containing Activity is updated

October 18, 2012 Posted by Anders Asp

Ever tried sending a notification to Affected User of the parent Work Item of an Activity when the Activity is updated? When trying to create this subscription from the SCSM console, you are faced with this when selecting the Related Recipient:

Holy cow! You are presented with a massive ammount of relationships to choose between! I tried a couple of relationships here without any luck, and figured that it would be easier to do this in the XML code.

So let’s say we have a Service Request with a number of activities in it. When one of these activities are completed, we want to notify the Affected User of the Service Request that the particular activity is completed.

  1. Go to Administration -> Notifications -> Subscriptions and click Create Subscription task.
  2. Click Next on the “Before you being” page.
  3. Give the Subscription a Name and Description. Chose to trigger the notification whenever an object is updated and as the targeted class, use an activity class. In this example I will work with the Review Activity class. Chose a Management Pack to store this Subscription in and click Next.

  4. Click Next at the Group/Queue Selection page.
  5. In the Additional Criteria, specify whenever you want this Subscription to trigger. I will trigger whenever the status of a Review Activity with a certain title changes. Click next.

  6. Select a Notification template to use when sending the notification and click Next.
  7. Click Next at the Recipient page.
  8. Now, at the Related Recipients, click Add and select the “Contains Activity” relationship. Then select the Affected User and click Add followed by Next.

    Note: When configured this way, the Subscription will actually try to notify the Affected User of any containing activities of the Review Activity! This is what we are going to change in the XML later on.
  9. Click Create followed by Close.
  10. Now, go to Administration -> Management Packs and locate the Management Pack in which you stored this Subscription. Export it by using the Export task.
  11. Open this exported Management Pack with your favorite XML editor (I use Notepad++ but regular Notepad will do it as well).
  12. Locate the Subscription within your MP and scroll down a couple of lines to the WriteActions section. Within this section you should have a couple of lines of code that looks like this:
    <WorkflowArrayParameter Name="PrimaryUserRelationships" Type="string">
    <Item>$Context/Path[Relationship='CustomSystem_WorkItem_Activity_Library!System.WorkItemContainsActivity' TypeConstraint='CustomSystem_WorkItem_Activity_Library!System.WorkItem.Activity']/Path[Relationship='CustomSystem_WorkItem_Library!System.WorkItemAffectedUser' TypeConstraint='CustomSystem_Library!System.User']$</Item>

    This is the code where we have to do some editing. We would like to reverse the Contains Acitivty relationship, so instead of looking at the Affected User of any containing acitivities of this particular Review Acitivty, we would like to select the Affected User of the Work Item in which this acivity is contained. (Hope that this make some kinde of sense?)Note: The easiest way to locate your Subscription is to search for the name you specified when it was created. This will take you to the DisplayString section where you want to copy the ElementID from the line above the subscription name. Now do a new search for this ElementID until you get to a row that starts with <Rules ID=”….

  13.  So to reverse the relationship we need to add SeedRole=’Target’ right after WorkItemContainsAcitivy relationship, like this:
    $Context/Path[Relationship='CustomSystem_WorkItem_Activity_Library!System.WorkItemContainsActivity' SeedRole='Target'

    Next we need to change the Work Item type we are working with. As of now it is specified as the Acitivity class, so let’s change it to the Work Item class instead.

    TypeConstraint='CustomSystem_WorkItem_Library!System.WorkItem']/Path[Relationship='CustomSystem_WorkItem_Library!System.WorkItemAffectedUser' TypeConstraint='CustomSystem_Library!System.User']$

    Note: Make sure you have the reference to System.WorkItem.Library specified in you MP. I’m referring to that MP with the Alias CustomSystem_WorkItem_Library because it was already present in my MP.

  14. And just to make it even more clear, here’s the code before we edited it:
    <WorkflowArrayParameter Name="PrimaryUserRelationships" Type="string">
    <Item>$Context/Path[Relationship='CustomSystem_WorkItem_Activity_Library!System.WorkItemContainsActivity' TypeConstraint='CustomSystem_WorkItem_Activity_Library!System.WorkItem.Activity']/Path[Relationship='CustomSystem_WorkItem_Library!System.WorkItemAffectedUser' TypeConstraint='CustomSystem_Library!System.User']$</Item>

    And here’s the code after we edited it:

    <WorkflowArrayParameter Name="PrimaryUserRelationships" Type="string">
    <Item>$Context/Path[Relationship='CustomSystem_WorkItem_Activity_Library!System.WorkItemContainsActivity' SeedRole='Target' TypeConstraint='CustomSystem_WorkItem_Library!System.WorkItem']/Path[Relationship='CustomSystem_WorkItem_Library!System.WorkItemAffectedUser' TypeConstraint='CustomSystem_Library!System.User']$</Item>

    And here it is in a picture, marked with the changes:

  15. Now save the changes and head back to the SCSM Console.
  16. Go to Administration -> Management Packs and Import the MP by using the Import task.
  17. Test your Subscription!

Please post a comment if you have any questions or if you want me to clarify anything! Oh, and by the way, if any of you managed to configure this from the console, please drop a comment as well! 😛

15 Responses to Send a notification the Affected User of a Work Item when a containing Activity is updated

Leave a Reply

Your email address will not be published. Required fields are marked *