Getting Projection Objects Using the SCSM SDK ObjectProjectionCriteria Class

Published Feb 15 2019 07:31 PM 604 Views
First published on TECHNET on Aug 23, 2013

Quick sample here.  Let’s say you want to get all the service requests assigned to a particular support group (enum data type property).  No problem!  Use ObjectProjectionCriteria .  That will get you projection objects.  If you want to just get objects you can use the related EnterpriseManagementObjectCriteria class.  ( what is a type projection/projection objects? )

Here are some more details:

http://blogs.msdn.com/b/scplat/archive/2010/12/27/using-sdk-criteria-querying-instances.aspx ...

Here are some examples that people have put out on the web.

http://scsmnz.net/c-code-snippets-for-service-manager-1/

http://scsmnz.net/c-code-snippets-for-service-manager-2/

http://blog.scsmsolutions.com/2011/09/codesnipets-for-scsm-2010-sdk/#Get_the_class_by_ID_Guid_o...

Party on!

Here’s the code for the project if you want to copy it:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.EnterpriseManagement;
using Microsoft.EnterpriseManagement.Configuration;
using Microsoft.EnterpriseManagement.Common;

namespace QuerySRsBySupportGroup
{
class Program
{
static void Main(string[] args)
{
//Create connection to Managment Server
EnterpriseManagementGroup emg = new EnterpriseManagementGroup("localhost");
//Get the SR Advanced type projection
ManagementPackTypeProjectionCriteria mptpcServiceRequestAdvanced =
new ManagementPackTypeProjectionCriteria("Name ='System.WorkItem.ServiceRequestProjection'");
ManagementPackTypeProjection mptpServiceRequestAdvanced =
emg.EntityTypes.GetTypeProjections(mptpcServiceRequestAdvanced).First<ManagementPackTypeProjection>();
//Get the SR Library MP
ManagementPackCriteria mpcServiceRequestMP =
new ManagementPackCriteria("Name = 'System.WorkItem.ServiceRequest.Library'");
ManagementPack mpServiceRequestLibrary =
emg.ManagementPacks.GetManagementPacks(mpcServiceRequestMP).First<ManagementPack>();
//Get a particular support group enumeration
ManagementPackEnumerationCriteria mpecSupportGroup =
new ManagementPackEnumerationCriteria("Name = 'Enum.cd96b8a5444b41d081e658ee0a90383c'");
ManagementPackEnumeration mpeSupportGroup =
emg.EntityTypes.GetEnumerations(mpecSupportGroup).First<ManagementPackEnumeration>();

//Create the criteria
string strCriteria =
String.Format(
@"<Criteria xmlns="" http://Microsoft.EnterpriseManagement.Core.Criteria/"" >
<Expression>
<SimpleExpression>
<ValueExpressionLeft>
<Property>$Context/Property[Type='System.WorkItem.ServiceRequest']/SupportGroup$</Property>
</ValueExpressionLeft>
<Operator>Equal</Operator>
< ValueExpressionRight>
<Value>{0}</Value>
</ValueExpressionRight>
</SimpleExpression>
</Expression>
< /Criteria>", mpeSupportGroup.Id.ToString());

//Create the ObjectProjectionCriteria.  Include the MP (mpServiceRequestLibrary) that the type projection seed class is contained in.
ObjectProjectionCriteria opc =
new ObjectProjectionCriteria(strCriteria, mptpServiceRequestAdvanced,mpServiceRequestLibrary, emg);
//Get the SRs
IObjectProjectionReader<EnterpriseManagementObject> oprServiceRequests =
emg.EntityObjects.GetObjectProjectionReader<EnterpriseManagementObject>(opc, ObjectQueryOptions.Default);
//Do whatever you want with them...
foreach (EnterpriseManagementObjectProjection emopServiceRequest in oprServiceRequests)
{
Console.WriteLine(emopServiceRequest.Object.Id);
}
Console.ReadLine();
}
}
}

%3CLINGO-SUB%20id%3D%22lingo-sub-348414%22%20slang%3D%22en-US%22%3EGetting%20Projection%20Objects%20Using%20the%20SCSM%20SDK%20ObjectProjectionCriteria%20Class%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-348414%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20TECHNET%20on%20Aug%2023%2C%202013%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CP%3EQuick%20sample%20here.%26nbsp%3B%20Let%E2%80%99s%20say%20you%20want%20to%20get%20all%20the%20service%20requests%20assigned%20to%20a%20particular%20support%20group%20(enum%20data%20type%20property).%26nbsp%3B%20No%20problem!%26nbsp%3B%20Use%20%3CA%20href%3D%22http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fgg461860.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20ObjectProjectionCriteria%20%3C%2FA%3E%20.%26nbsp%3B%20That%20will%20get%20you%20projection%20objects.%26nbsp%3B%20If%20you%20want%20to%20just%20get%20objects%20you%20can%20use%20the%20related%20%3CA%20href%3D%22http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fgg461769.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20EnterpriseManagementObjectCriteria%20%3C%2FA%3E%20class.%26nbsp%3B%20(%20%3CA%20href%3D%22http%3A%2F%2Fblogs.msdn.com%2Fb%2Fjakuboleksy%2Farchive%2F2009%2F01%2F20%2Fgetting-started-with-type-projections.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20what%20is%20a%20type%20projection%2Fprojection%20objects%3F%20%3C%2FA%3E%20)%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F80649i510F00C7A0957FC2%22%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3EHere%20are%20some%20more%20details%3A%3C%2FP%3E%0A%20%20%3CP%3E%3CA%20href%3D%22http%3A%2F%2Fblogs.msdn.com%2Fb%2Fscplat%2Farchive%2F2010%2F12%2F27%2Fusing-sdk-criteria-querying-instances.aspx%22%20title%3D%22http%3A%2F%2Fblogs.msdn.com%2Fb%2Fscplat%2Farchive%2F2010%2F12%2F27%2Fusing-sdk-criteria-querying-instances.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20http%3A%2F%2Fblogs.msdn.com%2Fb%2Fscplat%2Farchive%2F2010%2F12%2F27%2Fusing-sdk-criteria-querying-instances.aspx%20%3C%2FA%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EHere%20are%20some%20examples%20that%20people%20have%20put%20out%20on%20the%20web.%3C%2FP%3E%0A%20%20%3CP%3E%3CA%20href%3D%22http%3A%2F%2Fscsmnz.net%2Fc-code-snippets-for-service-manager-1%2F%22%20title%3D%22http%3A%2F%2Fscsmnz.net%2Fc-code-snippets-for-service-manager-1%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20http%3A%2F%2Fscsmnz.net%2Fc-code-snippets-for-service-manager-1%2F%20%3C%2FA%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CA%20href%3D%22http%3A%2F%2Fscsmnz.net%2Fc-code-snippets-for-service-manager-2%2F%22%20title%3D%22http%3A%2F%2Fscsmnz.net%2Fc-code-snippets-for-service-manager-2%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20http%3A%2F%2Fscsmnz.net%2Fc-code-snippets-for-service-manager-2%2F%20%3C%2FA%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CA%20href%3D%22http%3A%2F%2Fblog.scsmsolutions.com%2F2011%2F09%2Fcodesnipets-for-scsm-2010-sdk%2F%23Get_the_class_by_ID_Guid_or_name%22%20title%3D%22http%3A%2F%2Fblog.scsmsolutions.com%2F2011%2F09%2Fcodesnipets-for-scsm-2010-sdk%2F%23Get_the_class_by_ID_Guid_or_name%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20http%3A%2F%2Fblog.scsmsolutions.com%2F2011%2F09%2Fcodesnipets-for-scsm-2010-sdk%2F%23Get_the_class_by_ID_Guid_or_name%20%3C%2FA%3E%3C%2FP%3E%0A%20%20%3CP%3EParty%20on!%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EHere%E2%80%99s%20the%20code%20for%20the%20project%20if%20you%20want%20to%20copy%20it%3A%3C%2FP%3E%0A%20%20%3CP%3Eusing%20System%3B%20%3CBR%20%2F%3E%20using%20System.Collections.Generic%3B%20%3CBR%20%2F%3E%20using%20System.Linq%3B%20%3CBR%20%2F%3E%20using%20System.Text%3B%20%3CBR%20%2F%3E%20using%20Microsoft.EnterpriseManagement%3B%20%3CBR%20%2F%3E%20using%20Microsoft.EnterpriseManagement.Configuration%3B%20%3CBR%20%2F%3E%20using%20Microsoft.EnterpriseManagement.Common%3B%3C%2FP%3E%0A%20%20%3CP%3Enamespace%20QuerySRsBySupportGroup%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20class%20Program%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20static%20void%20Main(string%5B%5D%20args)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20%2F%2FCreate%20connection%20to%20Managment%20Server%20%3CBR%20%2F%3E%20EnterpriseManagementGroup%20emg%20%3D%20new%20EnterpriseManagementGroup(%22localhost%22)%3B%20%3CBR%20%2F%3E%20%2F%2FGet%20the%20SR%20Advanced%20type%20projection%20%3CBR%20%2F%3E%20ManagementPackTypeProjectionCriteria%20mptpcServiceRequestAdvanced%20%3D%20%3CBR%20%2F%3E%20new%20ManagementPackTypeProjectionCriteria(%22Name%20%3D'System.WorkItem.ServiceRequestProjection'%22)%3B%20%3CBR%20%2F%3E%20ManagementPackTypeProjection%20mptpServiceRequestAdvanced%20%3D%20%3CBR%20%2F%3E%20emg.EntityTypes.GetTypeProjections(mptpcServiceRequestAdvanced).First%3CMANAGEMENTPACKTYPEPROJECTION%3E()%3B%20%3CBR%20%2F%3E%20%2F%2FGet%20the%20SR%20Library%20MP%20%3CBR%20%2F%3E%20ManagementPackCriteria%20mpcServiceRequestMP%20%3D%20%3CBR%20%2F%3E%20new%20ManagementPackCriteria(%22Name%20%3D%20'System.WorkItem.ServiceRequest.Library'%22)%3B%20%3CBR%20%2F%3E%20ManagementPack%20mpServiceRequestLibrary%20%3D%20%3CBR%20%2F%3E%20emg.ManagementPacks.GetManagementPacks(mpcServiceRequestMP).First%3CMANAGEMENTPACK%3E()%3B%20%3CBR%20%2F%3E%20%2F%2FGet%20a%20particular%20support%20group%20enumeration%20%3CBR%20%2F%3E%20ManagementPackEnumerationCriteria%20mpecSupportGroup%20%3D%20%3CBR%20%2F%3E%20new%20ManagementPackEnumerationCriteria(%22Name%20%3D%20'Enum.cd96b8a5444b41d081e658ee0a90383c'%22)%3B%20%3CBR%20%2F%3E%20ManagementPackEnumeration%20mpeSupportGroup%20%3D%20%3CBR%20%2F%3E%20emg.EntityTypes.GetEnumerations(mpecSupportGroup).First%3CMANAGEMENTPACKENUMERATION%3E()%3B%3C%2FMANAGEMENTPACKENUMERATION%3E%3C%2FMANAGEMENTPACK%3E%3C%2FMANAGEMENTPACKTYPEPROJECTION%3E%3C%2FP%3E%0A%20%20%3CP%3E%2F%2FCreate%20the%20criteria%20%3CBR%20%2F%3E%20string%20strCriteria%20%3D%20%3CBR%20%2F%3E%20String.Format(%20%3CBR%20%2F%3E%20%40%22%3CCRITERIA%20xmlns%3D%22%26quot%3B%26quot%3B%22%3E%3CA%20href%3D%22http%3A%2F%2FMicrosoft.EnterpriseManagement.Core.Criteria%2F%26quot%3B%26quot%3B%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20http%3A%2F%2FMicrosoft.EnterpriseManagement.Core.Criteria%2F%22%22%20%3C%2FA%3E%20%26gt%3B%20%3CBR%20%2F%3E%20%3CEXPRESSION%3E%20%3CBR%20%2F%3E%20%3CSIMPLEEXPRESSION%3E%20%3CBR%20%2F%3E%20%3CVALUEEXPRESSIONLEFT%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%3E%24Context%2FProperty%5BType%3D'System.WorkItem.ServiceRequest'%5D%2FSupportGroup%24%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3C%2FVALUEEXPRESSIONLEFT%3E%20%3CBR%20%2F%3E%20%3COPERATOR%3EEqual%3C%2FOPERATOR%3E%20%3CBR%20%2F%3E%20%26lt%3B%20ValueExpressionRight%26gt%3B%20%3CBR%20%2F%3E%20%3CVALUE%3E%7B0%7D%3C%2FVALUE%3E%20%3CBR%20%2F%3E%20%3C%2FSIMPLEEXPRESSION%3E%20%3CBR%20%2F%3E%20%3C%2FEXPRESSION%3E%20%3CBR%20%2F%3E%20%3C%2FCRITERIA%3E%20%3CBR%20%2F%3E%20%26lt%3B%20%2FCriteria%26gt%3B%22%2C%20mpeSupportGroup.Id.ToString())%3B%3C%2FP%3E%0A%20%20%3CP%3E%2F%2FCreate%20the%20ObjectProjectionCriteria.%26nbsp%3B%20Include%20the%20MP%20(mpServiceRequestLibrary)%20that%20the%20type%20projection%20seed%20class%20is%20contained%20in.%20%3CBR%20%2F%3E%20ObjectProjectionCriteria%20opc%20%3D%20%3CBR%20%2F%3E%20new%20ObjectProjectionCriteria(strCriteria%2C%20mptpServiceRequestAdvanced%2CmpServiceRequestLibrary%2C%20emg)%3B%20%3CBR%20%2F%3E%20%2F%2FGet%20the%20SRs%20%3CBR%20%2F%3E%20IObjectProjectionReader%3CENTERPRISEMANAGEMENTOBJECT%3E%20oprServiceRequests%20%3D%20%3CBR%20%2F%3E%20emg.EntityObjects.GetObjectProjectionReader%3CENTERPRISEMANAGEMENTOBJECT%3E(opc%2C%20ObjectQueryOptions.Default)%3B%20%3CBR%20%2F%3E%20%2F%2FDo%20whatever%20you%20want%20with%20them...%20%3CBR%20%2F%3E%20foreach%20(EnterpriseManagementObjectProjection%20emopServiceRequest%20in%20oprServiceRequests)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20Console.WriteLine(emopServiceRequest.Object.Id)%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20Console.ReadLine()%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%7D%3C%2FENTERPRISEMANAGEMENTOBJECT%3E%3C%2FENTERPRISEMANAGEMENTOBJECT%3E%3C%2FP%3E%0A%20%0A%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-348414%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20TECHNET%20on%20Aug%2023%2C%202013%20Quick%20sample%20here.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-348414%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESystem%20Center%20Service%20Manager%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Mar 11 2019 09:57 AM
Updated by: