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! 😛

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

  1. Chris Ross says:

    Awesome job, I will see if I can pull it off in the console, but I think you are correct – this must be done via xml.

  2. John Grisewood says:

    Works like a charm.

    Thanks Anders, much appreciated!


  3. Casey Robertson says:

    Hi Anders,

    I’m having an error importing the XML. Getting the error referenced here:

    Just not sure how to fix or find the reference that it needs for this to work? I put all my custom stuff into this custom MP but I must not have any previous references that this requires.


  4. Anders Asp says:

    Hi Casey,

    Send me your MP and I’ll take a look 🙂


  5. adrian salone says:

    A minor note – I was getting errors when importing my updated XML, even though I had copied and pasted the code above into my file.

    Turns out that the XML importer didn’t like the tab characters I put in front of the edited line…(I was using Notepad++)

  6. Leo says:

    It’s failed to import the modifed xml to SCSM, can you please help me to look at it?

    The configuration specified for Module WA is not valid.
    : Incorrect expression specified: $Context/Path[Relationship=’CustomSystem_WorkItem_Activity_Library!System.WorkItemContainsActivity’ SeedRole=’Target’ TypeConstraint=’CustomSystem_WorkItem_Library!System.WorkItem’]/Path[Relationship=’CustomSystem_WorkItem_Library!System.WorkItemAssignedToUser’ TypeConstraint=’CustomSystem_Library!System.User’]$. Unable to resolve this expression. Check the expression for errors. (Hints: Check for correct character casing (upper case/lower case), mismatched “$” signs, double quotes(“), square brackets “[” or “]”). Here is a sample expression: $Context/Property[Type=’Windows!Microsoft.Windows.Computer’]/NetworkName$

  7. Pete says:

    I am using Manual Activities inside of Parallel Activities. I noticed you used a review Activity though. It doesn’t seem to be working for me, should it be?

    • Anders Asp says:

      Should work even if you use a MA. If you have the MA inside a PA though, you have another relationship to traverse, but it should still be doable.


  8. Josh P says:

    Hi Anders,

    I’m trying to use your above solution in a bit of a different fashion. I’m trying to create a notification for a Review Activity in Change Requests. I want to trigger a notification that goes to not only the RA Reviewers list but also the Creator of the Change Request associated with the RA.

    So here’s what I tried in the XML, but its still not working sending the notification to the Creator.

    $Context/Path[Relationship=’CustomSystem_WorkItem_Library!System.WorkItemCreatedByUser’ SeedRole=’Target’ TypeConstraint=’CustomSystem_WorkItem_Library!System.WorkItem’]/Path[Relationship=’CustomSystem_WorkItem_Library!System.WorkItemCreatedByUser’ TypeConstraint=’CustomSystem_Library!System.User’]$

    Any suggestions?


  9. Sam says:

    No issues with the import after the xml modification, but the subscription still doesn’t email the effected user of the parent service request. Any pointers? Thx.

  10. Jeron says:

    My ServiceManager.ActivityManagement.Configuration.xml inside contain this. How do I edit this? It cant seem to work even when I put SeedRole=’Target’

    $Context/Path[Relationship=’WorkItem!System.WorkItemAffectedUser’ TypeConstraint=’System!System.User’]$

  11. Jules says:

    This worked great for me but the issue I now have is that the notification template contains a link for the end user to view the parent Service Request in the Portal. This only goes to my requests and not to the individual request. The link I’m using is =”https://scsmdevportal.webapp.[servername].local/smportal/SitePages/My%20Requests.aspx?RequestId=$Context/?$Id$?”. Can anyone advise? Thanks

  12. Bob says:

    thanks Anders Asp for the wonderful blog , I have a question if i want to show the affected user value in the RA notification email , can i use this arguments to fetch it out from the parents work items :
    $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’]$

  13. Taha says:

    Works Like a Charm. Much Appreciated

  14. / says:

    This piece of writing will assist the internet viewers for creating new
    weblog or even a blog from start to end.

Leave a Reply

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