Using Under Operator for List Queries
Suppose you want to query all hardware related incidents using the following criteria:
<Criteria xmlns="https://Microsoft.EnterpriseManagement.Core.Criteria/">
<Expression>
<SimpleExpression>
<ValueExpressionLeft>
<Property>$Context/Property[Type='System.WorkItem.Incident']/Classification$</Property>
</ValueExpressionLeft>
<Operator>Equal</Operator>
<ValueExpressionRight>
<Value>{9C46171F-64A2-B33A-FBD3-D3ED9881CDF6}</Value>
</ValueExpressionRight>
</SimpleExpression>
</Expression>
</Criteria>
In the above, "9C46171F-64A2-B33A-FBD3-D3ED9881CDF6" is the ID of list "IncidentClassificationEnum.Hardware". This criteria works as expected as long as "IncidentClassificationEnum.Hardware" does not have any child lists appended. However, you may want to customize this list by adding more specific information, such as specifying what kind of hardware is related to incidents. Suppose this list hierarchy is changed as follows:
IncidentClassficationEnum.Hardware
|- IncidentClassficationEnum.Hardware.Disk
|- IncidentClassficationEnum.Hardware.Disk.HardDisk
|- IncidentClassficationEnum.Hardware.Disk.CD
|- IncidentClassficationEnum.Hardware.Memory
|- IncidentClassficationEnum.Hardware.CPU
Then you can create incidents and set the classification property as one of the above child lists. In this case, in order to get all hardware related incidents, you need to adapt your query criteria. In Service Manager 2010, your option was to use the 'In' operator:
<Criteria xmlns="https://Microsoft.EnterpriseManagement.Core.Criteria/">
<Expression>
<In>
<Property>$Context/Property[Type='System.WorkItem.Incident']/Classification$</Property>
<Values>
<Value>9C46171F-64A2-B33A-FBD3-D3ED9881CDF6</Value>
<Value>3D5430DC-EA64-C457-70D8-11D8257E0B58</Value>
<Value>3C272B6C-A330-9135-E836-4E787EDE8C7C</Value>
<Value>6185BF42-FBBA-4339-9AA9-DA0FDE48D881</Value>
<Value>E1ECB59B-A9F0-9ED4-B675-B4C1C8CE97FD</Value>
<Value>BCA04F7A-41E6-B053-6E40-EF4B02FDCCFD</Value>
</Values>
</In>
</Expression>
</Criteria>
In the above query, you have to collect all child list Ids as well as the parent list Id. Further, whenever you add more child lists, you need to change the criteria correspondingly. In Service Manager 2010 SP1, we introduce a new operator "Under" in which you only need to specify the root list ID. The criteria keeps working if any child item is added, deleted or updated from the corresponding hierarchy.
<Criteria xmlns="https://Microsoft.EnterpriseManagement.Core.Criteria/">
<Expression>
<SimpleExpression>
<ValueExpressionLeft>
<Property>$Context/Property[Type='System.WorkItem.Incident']/Classification$</Property>
</ValueExpressionLeft>
<Operator>Under</Operator>
<ValueExpressionRight>
<Value>{9C46171F-64A2-B33A-FBD3-D3ED9881CDF6}</Value>
</ValueExpressionRight>
</SimpleExpression>
</Expression>
</Criteria>
The under operator won't filter out the root list by default. The results of using the above criteria include all incidents whose classification is equal to IncidentClassificationEnum.Hardware. If you only want to get incidents related to specific hardware, then you have to exclude the root list explicitly:
<Criteria xmlns="https://Microsoft.EnterpriseManagement.Core.Criteria/">
<Expression>
<And>
<Expression>
<SimpleExpression>
<ValueExpressionLeft>
<Property>$Context/Property[Type='System.WorkItem.Incident']/Classification$</Property>
</ValueExpressionLeft>
<Operator>NotEqual</Operator>
<ValueExpressionRight>
<Value>{9C46171F-64A2-B33A-FBD3-D3ED9881CDF6}</Value>
</ValueExpressionRight>
</SimpleExpression>
</Expression>
<Expression>
<SimpleExpression>
<ValueExpressionLeft>
<Property>$Context/Property[Type='System.WorkItem.Incident']/Classification$</Property>
</ValueExpressionLeft>
<Operator>Under</Operator>
<ValueExpressionRight>
<Value>{9C46171F-64A2-B33A-FBD3-D3ED9881CDF6}</Value>
</ValueExpressionRight>
</SimpleExpression>
</Expression>
</And>
</Expression>
</Criteria>
This new operator has not been supported in UI criteria builder. In order to use it in SM console, you need to do the changes manually. Suppose you create a view to list all hardware incidents as shown below:
Notice that you cannot choose the 'Under' operator here. Instead, select the 'equals' operator for now. Next, export the management pack where you saved this view and edit the view criteria to change 'Equal' operator to 'Under'. After importing the updated management pack, click the above view and you are able to see all hardware related incidents there.
It is important to note that if you open the "edit view" dialog for the changed view, it still shows the 'Equals' operator in the criteria area. This means that if you make any subsequent changes to the criteria of the view through the console, it will overwrite the 'Under' operator and you will have to manually edit the criteria again.