Using And/Or Criteria in Workflow and Notification Subscriptions

Using And/Or Criteria in Workflow and Notification Subscriptions

  • Comments 4
  • Likes

First let’s make sure we understand some logical concepts related to criteria.  If I say the criteria for selecting a movie is:

Rating is greater than 4 stars

MPAA rating is not equal to Rated R

Genre is Comedy, Action, Drama

I am not being clear enough about what my criteria is.  Do I mean that the movie can meet any of those criteria and be acceptable?  Or do I mean that the movie must meet all of those criteria?  Does the movie have to be Comedy, Action, and Drama all in one?

What if I was more specific in my criteria and said:

(Rating is greater than 4 stars

AND

MPAA rating is not equal to Rated R

AND

(Genre is Comedy OR Action OR Drama))

If this was my criteria clearly something like Lord of The Rings: Two Towers would meet the criteria but something like Snakes on a Plane would not.  Snakes on a Plane is not rated 4 stars or better and is Rated R.  It could be considered an ‘Action’ movie or a ‘Comedy’ movie I guess depending on your point of view, but it doesn’t meet the other two criteria anyways so it’s out.

Now consider how grouping the clauses differently returns different results.

(Rating is greater than 4 stars

AND

MPAA rating is not equal to Rated R)

OR

(Genre is Comedy OR Action OR Drama)

With this criteria Snakes on a Plane could be considered to meet the criteria since it could be considered an action (or a comedy) movie and the movie either has to be a comedy, action or drama movie OR be both a 4+ stars movie an not rated R.

Now let’s apply this concept to workflow/subscription criteria…

When you are creating notification subscription criteria in the console each criteria that you add to the criteria builder is AND’ed together with other criteria.  For example I could say ‘when an incident is created and the source = Portal and the title contains ‘foo’ and the urgency = high like this:

image

If I want to I can OR multiple list values from the same list together by adding the list data type property to the criteria more than once and choosing different list values like this:

image

This is equivalent saying this:

(Source = Portal

AND

Title contains ‘Foo’

AND

(Urgency is High OR Medium))

Now – here is some criteria that a customer was trying to do:

clip_image002

The customer’s intention was to fire the workflow whenever the incident matched this criteria:

Source Does Not Equal ‘Portal’

AND

Source Does Not Equal ‘Console’

In other words ‘fire if source is anything except portal or console’. But because the criteria is OR’d together when you use multiple values from the same list it looks like this:

Source Does Not Equal ‘Portal’

OR

Source Does Not Equal ‘Console’

So – let’s take some examples – if the source is ‘Portal’ will this workflow be triggered? Yes! Because while it doesn’t meet the criteria in the first clause it does meet the criteria in the second clause and since they are OR’d together only one of them must be true to fire the workflow.  What if the source was ‘Console’?  The criteria would be met by the first criteria but not the second and so it would fire.  It would also fire if the source were ‘Email’ since it matches both criteria.  This is clearly not what the customer intended.  What to do?

Two options:

1) Since you are dealing with a finite set of sources you could create your criteria to look like this instead:

Source Equals ‘Email’

OR

Source Equals ‘Compliance’

OR

Source Equals ‘Phone’

OR

Source Equals ‘Configuration Manager (DCM)’

OR

Source Equals ‘System’

OR

Source Equals ‘Operations Manager’

Basically you are matching any criteria other than Console or Email.  That works in some cases where you have a relatively short finite list of items but it has some drawbacks.  If you ever added a new source to the list you would need to remember to update this criteria to include an OR clause for that as well.  It’s a little harder to tell at a glance what the conceptual intention of the criteria is.  Remember the conceptual intent of the criteria was to do something if the source was anything but Console or Portal.

2) You can export out the MP and change the XML from this:

                      <Or>
                        <Expression>
                          <SimpleExpression>
                            <ValueExpression>
                              <Property State="Post">$Context/Property[Type='CustomSystem_WorkItem_Incident_Library!System.WorkItem.Incident']/Source$</Property>
                            </ValueExpression>
                            <Operator>NotEqual</Operator>
                            <ValueExpression>
                              <Value>{6ef191ce-3124-2974-94fb-020c677f4017}</Value>
                            </ValueExpression>
                          </SimpleExpression>
                        </Expression>
                        <Expression>
                          <SimpleExpression>
                            <ValueExpression>
                              <Property State="Post">$Context/Property[Type='CustomSystem_WorkItem_Incident_Library!System.WorkItem.Incident']/Source$</Property>
                            </ValueExpression>
                            <Operator>NotEqual</Operator>
                            <ValueExpression>
                              <Value>{76480d55-a19d-7cef-4446-0f1ccaef11ce}</Value>
                            </ValueExpression>
                          </SimpleExpression>
                        </Expression>
                      </Or>

to this:

 

                      <And>
                        <Expression>
                          <SimpleExpression>
                            <ValueExpression>
                              <Property State="Post">$Context/Property[Type='CustomSystem_WorkItem_Incident_Library!System.WorkItem.Incident']/Source$</Property>
                            </ValueExpression>
                            <Operator>NotEqual</Operator>
                            <ValueExpression>
                              <Value>{6ef191ce-3124-2974-94fb-020c677f4017}</Value>
                            </ValueExpression>
                          </SimpleExpression>
                        </Expression>
                        <Expression>
                          <SimpleExpression>
                            <ValueExpression>
                              <Property State="Post">$Context/Property[Type='CustomSystem_WorkItem_Incident_Library!System.WorkItem.Incident']/Source$</Property>
                            </ValueExpression>
                            <Operator>NotEqual</Operator>
                            <ValueExpression>
                              <Value>{76480d55-a19d-7cef-4446-0f1ccaef11ce}</Value>
                            </ValueExpression>
                          </SimpleExpression>
                        </Expression>
                      </And>

Then, reimport the MP.

You can get MUCH fancier about your and/or criteria in XML than the UI will allow you for now. We’ll try to expand the possibilities of what the UI can handle in future releases but for now this is all you can do:

1) AND criteria from multiple properties together (e.g. Title contains ‘Foo’ AND Source equals ‘Email’)

2) OR list values from a single list together (e.g. Source equals ‘Email’ OR Source does not equal ‘Portal’ OR Source equals ‘Operations Manager’)

If you need more complicated criteria than that you can set up virtually anything in the XML as far as AND/OR criteria goes.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • <p>Hi Travis,</p> <p>What if you want to combine And and Or blocks?</p> <p>For example:</p> <p>(Status=Guid Or Status=Guid Or Status=Guid) And (Title Like &quot;test&quot;)</p> <p>I just can&#39;t seem to figure this out so the criteria are accepted...</p> <p>Cheers,</p> <p>Rob</p>

  • <p>@Travis, I have worked it out ok now, although I am baffled at how the criteria are treated within the &lt;And&gt; block!</p> <p>Cheers,</p> <p>Rob</p>

  • <p>Hi travis,</p> <p>I have this issue with the Not Equal of classification category to a change request workflow.</p> <p>I think this is the solution I need</p> <p>Wich Management Pack I have to export to replace the criteria ?</p> <p>thanks a lot</p>

  • <p>Hi, Travis</p> <p>I want to display the all incident scsm 2012 with following criteria.</p> <p>Impact = &#39;High&#39; OR &#39;Medium&#39; OR &#39;Low&#39;</p> <p>Urgency=&#39;High&#39; Or &#39;Medium&#39; OR &#39;Low&#39;</p> <p>and Enum should be &#39;Open&#39;.</p> <p>please write the xml criteria for it.</p> <p>Thank you in Advance</p> <p>--</p> <p>Shahnawaz</p>