Workflow/Notification Subscription NotEqual Criteria Across Pre/Post Condition
Published Feb 15 2019 03:44 AM 202 Views
First published on TECHNET on Aug 24, 2010

I’ve been meaning to blog this one for a while now.  Here’s the scenario…


Customer wants to be notified (or trigger a workflow) when the property changes from X to Y.  Easily done.  Just configure the subscription to be Before Value = X and After Value = Y.


Example:  Notify me whenever the incident urgency property changes from Medium to High looks like this:




This notification will only trigger when the Urgency property changes from Medium to High.  Perfect!  Easy!


Now, let’s say that you want to notify when the Urgency changes from anything to anything else.  How do you do that in the UI?  Believe me – people have tried all kinds of crazy things they have sent me.  :)  The answer is that you can’t do this in the UI.  Trick Question!  You can do this in XML though.  Here’s the trick….


First – start out by creating a notification subscription (what I did for this example) or an incident event workflow rule or create a workflow rule in the authoring tool.  Here are the screenshots of what I did:




Then export the MP out (see here for information on hacking XML like a pro ).  Open the MP .xml file in an XML editor.  Look for the Rule in there which you created.  Inside of it you will see the criteria XML that will look like this:


<UpdateInstance>





<Criteria>





<Expression>





<SimpleExpression>





<ValueExpression>





<Property State="Pre">$Context/Property[Type='CustomSystem_WorkItem_Library!System.WorkItem.TroubleTicket']/Urgency$</Property>



</ValueExpression>





<Operator>Equal</Operator>



<ValueExpression>





<Value>{02625c30-08c6-4181-b2ed-222fa473280e}</Value>



</ValueExpression>





</SimpleExpression>





</Expression>





</Criteria>





</UpdateInstance>






What you can see here is that the criteria is simply saying ‘Take the ‘Pre’ (i.e. before the update) value and see if that equals this GUID (represents the Medium Urgency Enum).  In other cases it might look a little different depending on your criteria.  What you need to do is change this to say ‘Compare the Pre value and the Post value. If they are not equal then trigger’.  Like this:



<UpdateInstance>





<Criteria>





<Expression>





<SimpleExpression>





<ValueExpression>





<Property State="Pre">$Context/Property[Type='CustomSystem_WorkItem_Library!System.WorkItem.TroubleTicket']/Urgency$</Property>



</ValueExpression>





<Operator>NotEqual</Operator>



<ValueExpression>





<Property State="Post">$Context/Property[Type='CustomSystem_WorkItem_Library!System.WorkItem.TroubleTicket']/Urgency$</Property>



</ValueExpression>





</SimpleExpression>





</Expression>





</Criteria>





</UpdateInstance>




I changed three things:


1) Change the Operator from Equal to NotEqual


2) Copied the Property State = Pre line and replaced the <Value>{Guid…}</Value> line with it.


3) In the second reference to the Property I changed the State from “Pre” to “Post”




Now I can just reimport this MP and it should start working as expected.



Note : As with any runtime changes you make to unsealed MPs, you’ll either need to increment the version number in the MP XML before import or restart the health service (System Center Management Service) before the change will take effect.



Note2: Not surprisingly, if you do this the UI will be confused.  If you open the properties dialog to edit the subscription you will probably see an error like this:



Hint: There are other tricky things you can do in Subscription Criteria XML that you can’t do in the UI like Relationship Add/Remove subscriptions .


My finished test/example MP is attached.



Apparently this reply to @jalass is too long to put in the Comments section below so I'll just add it to the end of the blog post here:


@jalass-


First of all - couldnt agree with you more on this needing to be in the UI.  We'll get there.  Just couldnt build Rome in a day.


Work Item Assigned to User is a generic relationship type between any work item class and the user class.  So - to subscribe to Change Request assignment changes you would just change:


<RelationshipSubscription RelType="$MPElement[Name='WorkItem!System.WorkItemAssignedToUser']$" SourceType="$MPElement[Name='CoreActivity!System.WorkItem.Activity']$" TargetType="$MPElement[Name='System!System.Domain.User']$">


to:
<RelationshipSubscription RelType="$MPElement[Name='WorkItem!System.WorkItemAssignedToUser']$" SourceType="$MPElement[Name='CoreChangeRequest!System.WorkItem.ChangeRequest']$" TargetType="$MPElement[Name='System!System.Domain.User']$">


In case it isnt obvious, I just changed CoreActivity!System.WorkItem.Activity to CoreChangeRequest!System.WorkItem.ChangeRequest.  In that case make sure you have an MP reference that maps 'CoreChangeRequest' to the System.WorkItem.ChangeRequest.Library MP like this:
<Reference Alias="CoreChangeRequest">
<ID>System.WorkItem.ChangeRequest.Library</ID>
<Version>7.0.5826.0</Version>
<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</Reference>


You could do the same thing for problems by changing it to CoreProblem!System.WorkItem.Problem and adding the right reference like this:
<Reference Alias="CoreProblem">
<ID>System.WorkItem.Problem.Library</ID>
<Version>7.0.5826.0</Version>
<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
</Reference>


You can subscribe to different relationship types such as Created By and Affected User by looking up the appropriate relationship type ID and replacing that in the part that says WorkItem!System.WorkItemAssignedToUser above.  Make sure you have the right MP reference in place for the MP that you are getting the relationship type from.


Here is the info you need for the Created By and Affected User relationship types:


Created By Relationship Type ID: System.WorkItemCreatedByUser
Created By Relationship Type MP ID: System.WorkItem.Library


Affected User Relationship Type ID: System.WorkItemAffectedUser
Affected User Relationship Type MP ID: System.WorkItem.Library


BTW - Created By should never change.  :)


If you want to send a notification to a group you have two options -
1) Put the user in as the Affected User, Assigned To User and use the above approach.
2) Create a notification subscription (Administration - Notifications - Subscriptions).  Choose the group you want to notify in the recipients page of the wizard.  Note: the group must have an associated email address.  The export the MP and change the criteria as explained in the other blog post.  Reimport the MP.














ManagementPack.d8fd96a9470c4942a127c3860ea377d0.xml

Version history
Last update:
‎Mar 11 2019 08:31 AM
Updated by: