Hello,
I'm trying to retrieve all child incidents of a specific incident (to show more details than the default "ChildIncidents" tab in the default Incident form), but unable to enumerate them.
I've tried using both the System.WorkItem.Projection and the System.WorkItem.ChildIncident.ProjectionType projection type with no luck. The code contains both methods tried.
static void Main(string[] args)
{
string strIRID = "IR82210";
// connect to management group
EnterpriseManagementGroup mg = new EnterpriseManagementGroup("SM12-NLB");
string strCriteria = @"<Criteria xmlns='http://Microsoft.EnterpriseManagement.Core.Criteria/'>
<Reference Id='System.WorkItem.Library' PublicKeyToken='{0}' Version='{1}' Alias='WorkItem' />
<Expression>
<SimpleExpression>
<ValueExpressionLeft>
<Property>$Context/Property[Type='System.WorkItem.Incident']/Id$</Property>
</ValueExpressionLeft>
<Operator>Equal</Operator>
<ValueExpressionRight>
<Value>{2}</Value>
</ValueExpressionRight>
</SimpleExpression>
</Expression>
</Criteria>";
ManagementPackCriteria mpCr = new ManagementPackCriteria("Name = 'System.WorkItem.Incident.Library'");
IList<ManagementPack> mps = mg.ManagementPacks.GetManagementPacks(mpCr);
ManagementPack incidentMp = mps != null && mps.Count > 0 ? mps[0] : null;
ManagementPackClassCriteria classCr = new ManagementPackClassCriteria("Name = 'System.WorkItem.Incident'");
IList<ManagementPackClass> classes = mg.EntityTypes.GetClasses(classCr);
ManagementPackClass incidentCl = classes != null && classes.Count > 0 ? classes[0] : null;
//ManagementPackTypeProjectionCriteria tpCr = new ManagementPackTypeProjectionCriteria("Name = System.WorkItem.ChildIncident.ProjectionType'");
ManagementPackTypeProjectionCriteria tpCr = new ManagementPackTypeProjectionCriteria("Name = 'System.WorkItem.Projection'");
IList<ManagementPackTypeProjection> projList = mg.EntityTypes.GetTypeProjections(tpCr);
ManagementPackTypeProjection incidentProj = projList != null && projList.Count > 0 ? projList[0] : null;
if (incidentMp != null && incidentCl != null && incidentProj != null)
{
string criteria = string.Format(strCriteria, incidentMp.KeyToken, incidentMp.Version, strIRID);
ObjectProjectionCriteria cr = new ObjectProjectionCriteria(criteria, incidentProj, incidentMp, mg);
IObjectProjectionReader<EnterpriseManagementObject> reader = mg.EntityObjects.GetObjectProjectionReader<EnterpriseManagementObject>(cr, ObjectQueryOptions.Default);
foreach (EnterpriseManagementObjectProjection proj in reader)
{
Console.WriteLine(proj.Object[null, "Title"]);
Console.WriteLine(proj["RequestedWorkItem"][0].Object[null, "Domain"]);
Console.WriteLine(proj["RequestedWorkItem"][0].Object[null, "UserName"]);
Console.WriteLine(proj["ChildWorkItem"][0].Object[null, "Id"]);
}
}
There are a few ways documented out there on how to retrieve relationship objects, but tried them all with no luck
Hope anyone can help me.
Thanks