none
Get type projection objects with multiple references and a custom MP

    Question

  • I have created a view based on a custom MP and then used the criteria in the following code. This view checkes a customerCode called "CustomerDL" and also Status of the incident. Moreovre, we search for the relation of incidents based on the target relation ID.

    Here is the View Code:

    Now I have used the above code in my program:

    EnterpriseManagementGroup

    mg = new EnterpriseManagementGroup("IPAddress");               

    Version verMP = new Version("7.0.6555.0");               

    // Retrieve all the necessary management packs that hold the classes/relationships/type projections we'll need              

    ManagementPack mpSystem = mg.ManagementPacks.GetManagementPack(SystemManagementPack.System);               

    ManagementPack mpIncidentLibrary = mg.ManagementPacks.GetManagementPack(new Guid("DD26C521-7C2D-58C0-0980-DAC2DACB0900"));               

    ManagementPack mpIncidentManagementLibrary = mg.ManagementPacks.GetManagementPack("ServiceManager.IncidentManagement.Configuration", null, verMP);               

    ManagementPack mpWorkItemLibrary = mg.ManagementPacks.GetManagementPack("System.WorkItem.Library", "31bf3856ad364e35", verMP);               

    // Retrieve the classes/relationship/type projection from the management packs               

    ManagementPackClass mpcIncident = mpIncidentLibrary.GetClass("System.WorkItem.Incident");               

    ManagementPackTypeProjection mptpIncident = mg.EntityTypes.GetTypeProjection(new Guid("1862825e-21bc-3ab2-223e-2a7f2439ba75"));              

    // Define our criteria.               

    String strIncidentCriteria = @"<Criteria xmlns='http://Microsoft.EnterpriseManagement.Core.Criteria/'>

                          <Reference Id='System.WorkItem.Library' Version='7.0.6555.0' PublicKeyToken='31bf3856ad364e35' Alias='CustomSystem_WorkItem_Library'/>                      <Reference Id='SG.WorkItem.Incident.Properties' Version='1.0.0.21' PublicKeyToken='6334bc826c2a9405' Alias='CustomSG_WorkItem_Incident_Properties'/>

                          <Reference Id='System.WorkItem.Incident.Library' Version='7.0.6555.0' PublicKeyToken='31bf3856ad364e35' Alias='CustomSystem_WorkItem_Incident_Library'/>

                          <Expression>

                            <And>

                              <Expression>

                                <SimpleExpression>

                                  <ValueExpressionLeft>

                                    <Property>$Context/Property[Type='CustomSG_WorkItem_Incident_Properties!ClassExtension_260b17eb_c9ba_4462_9a64_0274ed828079']/CustomerDL$</Property>

                                  </ValueExpressionLeft>

                                  <Operator>Equal</Operator>

                                  <ValueExpressionRight>

                                    <Value>214736</Value>

                                  </ValueExpressionRight>

                                </SimpleExpression>

                              </Expression>

                              <Expression>

                                <SimpleExpression>

                                  <ValueExpressionLeft>

                                    <Property>$Context/Property[Type='CustomSystem_WorkItem_Incident_Library!System.WorkItem.Incident']/Status$</Property>

                                  </ValueExpressionLeft>

                                  <Operator>Equal</Operator>

                                  <ValueExpressionRight>

                                    <Value>{{f80d32a2-bda8-fc0a-05b9-1962a2e51213}}</Value>

                                  </ValueExpressionRight>

                                </SimpleExpression>

                              </Expression>

                              <Expression>

                                <SimpleExpression>

                                  <ValueExpressionLeft>

                                    <Property>$Context/Path[Relationship='CustomSystem_WorkItem_Library!System.WorkItemRelatesToWorkItem' TypeConstraint='CustomSystem_WorkItem_Library!System.WorkItem']/Property[Type='CustomSystem_WorkItem_Library!System.WorkItem']/Id$</Property>

                                  </ValueExpressionLeft>

                                  <Operator>Equal</Operator>

                                  <ValueExpressionRight>

                                    <Value>12295</Value>

                                  </ValueExpressionRight>

                                </SimpleExpression>

                              </Expression>

                            </And>

                          </Expression>

                        </Criteria>";

    // Perform the query

    ObjectProjectionCriteria opcIncidents = new ObjectProjectionCriteria(strIncidentCriteria, mptpIncident, mpIncidentLibrary, mg); 

    IObjectProjectionReader<EnterpriseManagementObject> oprIncidents = mg.EntityObjects.GetObjectProjectionReader<EnterpriseManagementObject>(opcIncidents, ObjectQueryOptions.Default);               

          

    But I get the following Exception:

    Cannot resolve identifier CustomSG_WorkItem_Incident_Properties!ClassExtension_260b17eb_c9ba_4462_9a64_0274ed828079 in the context of management pack System.WorkItem.Incident.Library. Unknown alias: CustomSG_WorkItem_Incident_Properties

    If I call the above code in this way

    new ObjectProjectionCriteria(Criteria, incident , mg) {Without MP Class)

    I get the following error:

    {"Cannot resolve identifier CustomSystem_WorkItem_Incident_Library!System.WorkItem.Incident in the context of management pack Test. Unknown alias: CustomSystem_WorkItem_Incident_Library"} Which I think means that it has managed to understand the CustomSG_Workitem_Incident_Properties reference because it comes first in the criteria section and error has movd on. I am very confused. Thanks


    YSobhdel



    • Edited by YSobhdel Sunday, April 15, 2012 1:15 PM
    Sunday, April 15, 2012 1:10 PM

Answers

  • I've tested some criteria and code very similar to yours and this works, only real difference is I don't add my references as I am using MP Guids directly:

    <Criteria xmlns="http://Microsoft.EnterpriseManagement.Core.Criteria/">
      <Expression>
        <And>
          <Expression>
            <SimpleExpression>
              <ValueExpressionLeft>
                <Property>$Context/Property[Type='System.WorkItem.Incident']/Status$</Property>
              </ValueExpressionLeft>
              <Operator>Equal</Operator>
              <ValueExpressionRight>
                <Value>5e2d3932-ca6d-1515-7310-6f58584df73e</Value>
              </ValueExpressionRight>
            </SimpleExpression>
          </Expression>
          <Expression>
            <SimpleExpression>
              <ValueExpressionLeft>
                <Property>$Context/Path[Relationship='WorkItem!System.WorkItemAssignedToUser' TypeConstraint='System!System.Domain.User']/Property[Type='System!System.Domain.User']/UserName$</Property>
              </ValueExpressionLeft>
              <Operator>Equal</Operator>
              <ValueExpressionRight>
                <Value>test</Value>
              </ValueExpressionRight>
            </SimpleExpression>
          </Expression>
          <Expression>
            <SimpleExpression>
              <ValueExpressionLeft>
                <Property>$Context/Property[Type='02176532-f0a4-2adf-255f-42c78859bbe5']/Type$</Property>
              </ValueExpressionLeft>
              <Operator>Equal</Operator>
              <ValueExpressionRight>
                <Value>37bba8ef-2517-c6a2-989c-d1a37a0fa6e6</Value>
              </ValueExpressionRight>
            </SimpleExpression>
          </Expression>
        </And>
      </Expression>
    </Criteria>

    I see you are using the incident typical type projection which does not contain System.WorkItemRelatesToWorkItem.

    Try using the advanced one, Guid is 285cb0a2-f276-bccb-563e-bb721df7cdec instead. If that fails, there are some additional incident type projections available here:
    http://blogs.technet.com/b/servicemanager/archive/2010/12/02/faq-why-is-my-custom-incident-view-so-slow.aspx

    Otherwise, if this criteria works for a view, I'm not sure why it is not working in your code, perhaps it will help to narrow it down. Start with say one expression and get that working, and then start adding the others and try and work out why it's not working.

    Have you definately got the correct Guids? My List Guids tool can be helpful in checking these:
    http://gallery.technet.microsoft.com/Tool-to-list-Guids-of-e33ca89b


    Rob Ford scsmnz.net



    Wednesday, April 18, 2012 7:03 AM

All replies

  • Try replacing:

    <Property>$Context/Property[Type='CustomSG_WorkItem_Incident_Properties!ClassExtension_260b17eb_c9ba_4462_9a64_0274ed828079']/CustomerDL$</Property>

    With:

    <Property>$Context/Property[Type='Your-Class-Extension-MP-Guid']/CustomerDL$</Property>


    Rob Ford scsmnz.net

    Tuesday, April 17, 2012 8:01 PM
  • Hi Rob

    I found the management pack id in the database. Since the name of Type in the

    <Property>$Context/Property[Type='CustomSG_WorkItem_Incident_Properties!ClassExtension_260b17eb_c9ba_4462_9a64_0274ed828079']/CustomerDL$</Property>

    is CustomSG_WorkItem_Incident_Properties and regarding

    <Reference Id='SG.WorkItem.Incident.Properties' Version='1.0.0.21' PublicKeyToken='6334bc826c2a9405' Alias='CustomSG_WorkItem_Incident_Properties'/>

    I searched for "SG.WorkItem.Incident.Properties" and did as you said but the following error occured:

    {"The provided path ($Context/Property[Type='39FE9E90-51CE-04C2-957D-CC4CA7794517']/CustomerDL$) was not valid: Property reference 'An object of class ManagementPackClass with ID 39fe9e90-51ce-04c2-957d-cc4ca7794517 was not found.' could not be resolved: Property[Type='39FE9E90-51CE-04C2-957D-CC4CA7794517']/CustomerDL$\r\nParameter name: pathReference"}

    I have posted a duplicate of this question in the following post:

    http://social.technet.microsoft.com/Forums/en-US/customization/thread/c5474011-ca9f-4937-8afb-593f15dd91da/#7f60eda1-a8eb-4ba5-a058-9f1e70ff62c4

    Thanks for your post


    YSobhdel

    Wednesday, April 18, 2012 3:50 AM
  • I've tested some criteria and code very similar to yours and this works, only real difference is I don't add my references as I am using MP Guids directly:

    <Criteria xmlns="http://Microsoft.EnterpriseManagement.Core.Criteria/">
      <Expression>
        <And>
          <Expression>
            <SimpleExpression>
              <ValueExpressionLeft>
                <Property>$Context/Property[Type='System.WorkItem.Incident']/Status$</Property>
              </ValueExpressionLeft>
              <Operator>Equal</Operator>
              <ValueExpressionRight>
                <Value>5e2d3932-ca6d-1515-7310-6f58584df73e</Value>
              </ValueExpressionRight>
            </SimpleExpression>
          </Expression>
          <Expression>
            <SimpleExpression>
              <ValueExpressionLeft>
                <Property>$Context/Path[Relationship='WorkItem!System.WorkItemAssignedToUser' TypeConstraint='System!System.Domain.User']/Property[Type='System!System.Domain.User']/UserName$</Property>
              </ValueExpressionLeft>
              <Operator>Equal</Operator>
              <ValueExpressionRight>
                <Value>test</Value>
              </ValueExpressionRight>
            </SimpleExpression>
          </Expression>
          <Expression>
            <SimpleExpression>
              <ValueExpressionLeft>
                <Property>$Context/Property[Type='02176532-f0a4-2adf-255f-42c78859bbe5']/Type$</Property>
              </ValueExpressionLeft>
              <Operator>Equal</Operator>
              <ValueExpressionRight>
                <Value>37bba8ef-2517-c6a2-989c-d1a37a0fa6e6</Value>
              </ValueExpressionRight>
            </SimpleExpression>
          </Expression>
        </And>
      </Expression>
    </Criteria>

    I see you are using the incident typical type projection which does not contain System.WorkItemRelatesToWorkItem.

    Try using the advanced one, Guid is 285cb0a2-f276-bccb-563e-bb721df7cdec instead. If that fails, there are some additional incident type projections available here:
    http://blogs.technet.com/b/servicemanager/archive/2010/12/02/faq-why-is-my-custom-incident-view-so-slow.aspx

    Otherwise, if this criteria works for a view, I'm not sure why it is not working in your code, perhaps it will help to narrow it down. Start with say one expression and get that working, and then start adding the others and try and work out why it's not working.

    Have you definately got the correct Guids? My List Guids tool can be helpful in checking these:
    http://gallery.technet.microsoft.com/Tool-to-list-Guids-of-e33ca89b


    Rob Ford scsmnz.net



    Wednesday, April 18, 2012 7:03 AM
  • private IObjectProjectionReader<EnterpriseManagementObject> getIncidentProjectionReader(string CusomerDL) { try { EnterpriseManagementGroup emg = new EnterpriseManagementGroup("ServerName"); Version verMP = new Version("7.0.6555.0"); // Retrieve all the necessary management packs that hold the classes/relationships/type projections we'll need ManagementPack mpSystem = emg.ManagementPacks.GetManagementPack(SystemManagementPack.System); ManagementPack mpIncidentLibrary = emg.ManagementPacks.GetManagementPack(new Guid("DD26C521-7C2D-58C0-0980-DAC2DACB0900")); ManagementPack mpIncidentManagementLibrary = emg.ManagementPacks.GetManagementPack("ServiceManager.IncidentManagement.Configuration", null, verMP); ManagementPack mpWorkItemLibrary = emg.ManagementPacks.GetManagementPack("System.WorkItem.Library", "31bf3856ad364e35", verMP); // Retrieve the classes/relationship/type projection from the management packs ManagementPackClass mpcIncident = mpIncidentLibrary.GetClass("System.WorkItem.Incident"); //ManagementPackTypeProjection mptpIncident = emg.EntityTypes.GetTypeProjection(new Guid("1862825e-21bc-3ab2-223e-2a7f2439ba75")); ManagementPackTypeProjection mptpIncident = emg.EntityTypes.GetTypeProjection(new Guid("285cb0a2-f276-bccb-563e-bb721df7cdec")); // Define our criteria. String strIncidentCriteria = @"<Criteria xmlns='http://Microsoft.EnterpriseManagement.Core.Criteria/'> <Expression> <And> <Expression> <SimpleExpression> <ValueExpressionLeft> <Property>$Context/Property[Type='d30dfee9-639f-2c00-8b4b-2ab755806140']/CustomerDL$</Property> </ValueExpressionLeft> <Operator>Equal</Operator> <ValueExpressionRight> <Value>214736</Value> </ValueExpressionRight> </SimpleExpression> </Expression> <Expression> <SimpleExpression> <ValueExpressionLeft> <Property>$Context/Property[Type='a604b942-4c7b-2fb2-28dc-61dc6f465c68']/Status$</Property> </ValueExpressionLeft> <Operator>Equal</Operator> <ValueExpressionRight> <Value>{f80d32a2-bda8-fc0a-05b9-1962a2e51213}</Value> </ValueExpressionRight> </SimpleExpression> </Expression> <Expression> <SimpleExpression> <ValueExpressionLeft> <Property>$Context/Path[Relationship='cb6ce813-ea8d-094d-ee5a-b755701f4547' TypeConstraint='a604b942-4c7b-2fb2-28dc-61dc6f465c68']/Property[Type='a604b942-4c7b-2fb2-28dc-61dc6f465c68']/Id$</Property> </ValueExpressionLeft> <Operator>Equal</Operator> <ValueExpressionRight> <Value>12295</Value> </ValueExpressionRight> </SimpleExpression> </Expression> </And> </Expression> </Criteria>";

    //You may Replace the 12295 with the Passed CustomerDL!

    // Perform the query ObjectProjectionCriteria opcIncidents = new ObjectProjectionCriteria(strIncidentCriteria, mptpIncident, mpIncidentLibrary, emg); IObjectProjectionReader<EnterpriseManagementObject> oprIncidents = emg.EntityObjects.GetObjectProjectionReader<EnterpriseManagementObject>(opcIncidents, ObjectQueryOptions.Default); return oprIncidents; } catch (Exception ex) { LogEvent(ex.Message, EventLogEntryType.Warning); return null; } finally { } }

    Thanks Rob. Finally I made thanks to your tools and replacement of class names with GUIDs. Also I used the advanced incident class as well. I posted the whole function so that the others may use it easily. Please inform me of any mistakes in the code but it works for sure!


    YSobhdel


    • Edited by YSobhdel Wednesday, April 18, 2012 11:19 AM Typos
    Wednesday, April 18, 2012 11:18 AM