none
Create Service Request from Request Offer meet Exception

    Question

  • HI All,

    I want to create a Service Request from Request Offer, but when i Commit the relationship with ServiceRequest and  RequestOffer, I get the Exception: 

    Cannot process extension elements as EnterpriseManagementObject. User EnterpriseManagementObjectProjection for all extension element CRUD operations.

    Anybody can give me some sugesstion:

    using (EnterpriseManagementGroup managementGroup = new EnterpriseManagementGroup(managementServer))
                    {
                        this.systemMp = managementGroup.ManagementPacks.GetManagementPack(SystemManagementPack.System);
                        Version version = systemMp.Version;
                        string keyToken = systemMp.KeyToken;                  
                        ServiceRequestMP = GetLatestManagementPack(ServiceRequestMpId, managementGroup);
                        ManagementPackClass mpOfferingClass =
                            ServiceRequestMP.GetClass("System.WorkItem.ServiceRequest");
                        ManagementPack mpRequestOfferings;
                        mpRequestOfferings = GetLatestManagementPack("System.ServiceCatalog.Library", managementGroup);
                        
                        changeProjection = new EnterpriseManagementObjectProjection(managementGroup, mpOfferingClass);
                        var temps = managementGroup.Templates.GetObjectTemplates();
                        ManagementPackObjectTemplate template = null;
                        foreach (var item in temps)
                        {
                            if (item.DisplayName == "CreatePVD_SRTemplate")
                            //if (item.DisplayName == "JustForEmialTest")
                            {
                                template = item;
                                break;
                            }
                        }
                        changeProjection.ApplyTemplate(template);
                        // Create the identifier for the change.
                        string changeId = "SR{0}";
                        // Properly set up the seed property values.
                        changeProjection.Object[mpOfferingClass, "Id"].Value = changeId;
                        changeProjection.Object[mpOfferingClass, "DisplayName"].Value = changeProjection.Object[mpOfferingClass, "Id"].Value + ": Automatically Provision New VM";
                        //  }
                        object strDisplayName = changeProjection.Object[mpOfferingClass, "DisplayName"].Value;
                        object strID = changeProjection.Object[mpOfferingClass, "Id"].Value;
                        CreatableEnterpriseManagementObject SMServiceRequest = new CreatableEnterpriseManagementObject(managementGroup, mpOfferingClass);
                        
                        string userInput = String.Format(@"<UserInput:<UserInputs>
                                                              <UserInput Question=""TemplateName"" Answer=""725t"" Type=""string"" />
                                                              <UserInput Question=""UserName"" Answer=""weili"" Type=""string"" />
                                                              <UserInput Question=""NewVMName"" Answer=""jurt"" Type=""string"" />
                                                              <UserInput Question=""Server"" Answer=""vmhostz"" Type=""string"" />
                                                          </UserInputs>");
                        ManagementPackEnumeration urglyEnum = null;
                        ManagementPackEnumeration priorityEnum = null;
                        ManagementPackEnumeration StatusEnum =null;
                        foreach (ManagementPackEnumeration curEnum in managementGroup.EntityTypes.GetEnumerations())
                        {
                            if (curEnum.ToString() == "ServiceRequestUrgencyEnum.Low")
                            {
                                urglyEnum = curEnum;
                            }
                            if (curEnum.ToString() == "ServiceRequestPriorityEnum.Low")
                            {
                                priorityEnum = curEnum;
                            }
                            if (curEnum.ToString() == "ServiceRequestStatusEnum.InProgress")
                            {
                                StatusEnum = curEnum;
                            }                        
                        }
                        changeProjection.Object[mpOfferingClass, "Title"].Value = "JustForEmailTest022";
                        changeProjection.Object[mpOfferingClass, "CreatedDate"].Value = DateTime.Now;                                        
                        changeProjection.Object[mpOfferingClass, "DisplayName"].Value = strDisplayName;                    
                        changeProjection.Object[mpOfferingClass, "CompletedDate"].Value = DateTime.Now.AddDays(2);
                        changeProjection.Object[mpOfferingClass, "ClosedDate"].Value = DateTime.Now.AddDays(3);
                        changeProjection.Object[mpOfferingClass, "Status"].Value = StatusEnum;
                        changeProjection.Object[mpOfferingClass, "TemplateId"].Value = template.ToString();
                        // SMServiceRequest[mpOfferingClass, "ID"].Value = strID;
                        //SMServiceRequest[mpOfferingClass, "Urgency"].Value = urglyEnum;
                        //SMServiceRequest[mpOfferingClass, "Priority"].Value = priorityEnum;
                        // SMServiceRequest[mpOfferingClass, "Source"].Value = request.Source;
                        // SMServiceRequest[mpOfferingClass, "ImplementationResults"].Value = request.ImplementationResult;
                        //changeProjection.Object[mpOfferingClass, "Notes"].Value = "Test";
                        // SMServiceRequest[mpOfferingClass, "Area"].Value = request.Area;
                        //  SMServiceRequest[mpOfferingClass, "SupportGroup"].Value = request.SupportGroup;
                        //  SMServiceRequest[mpOfferingClass, "Priority"].Value = request.priority;
                        //changeProjection.Object[mpOfferingClass, "RequiredBy"].Value = "vdi.com\\administrator";
                        //changeProjection.Object[mpOfferingClass, "UserInput"].Value = userInput;
                        //SMServiceRequest.Commit();
                        changeProjection.Commit();
                        String strIncidentByTitleCriteria =
                  String.Format(@"<Criteria xmlns=""http://Microsoft.EnterpriseManagement.Core.Criteria/"">" +
                        "<Expression>" +
                          "<SimpleExpression>" +
                            "<ValueExpressionLeft>" +
                              "<Property>$Target/Property[Type='System.WorkItem.ServiceRequest']/Id$</Property>" +
                            "</ValueExpressionLeft>" +
                            "<Operator>Equal</Operator>" +
                            "<ValueExpressionRight>" +
                              "<Value>" + strID + "</Value>" +
                            "</ValueExpressionRight>" +
                          "</SimpleExpression>" +
                        "</Expression>" +
                      "</Criteria>");
                        /*------------------------------------------------------------------------------------*/
                        /*--------------  // RelationShipType = System.WorkItemRelatesToRequestOffering ----------------------------------*/
                        ManagementPackRelationship relworkitem2RequestOffering =
                      managementGroup.EntityTypes.GetRelationshipClass(new Guid("2730587f-3d88-a4e4-42d8-08cf94535a6e"));
                        EnterpriseManagementObjectCriteria emorequestcriteria = new EnterpriseManagementObjectCriteria((String)strIncidentByTitleCriteria, mpOfferingClass, ServiceRequestMP, managementGroup);
                        IObjectReader<EnterpriseManagementObject> orworkitemRequest = managementGroup.EntityObjects.GetObjectReader<EnterpriseManagementObject>(emorequestcriteria, ObjectQueryOptions.Default);
                        EnterpriseManagementObject emoSRWorkitem = orworkitemRequest.ElementAt(0);
                        ServiceofferingMP = GetLatestManagementPack(ServiceOfferingMpId, managementGroup);
                        //Load the class from the management pack
                        ManagementPackClass mpRequestOfferingClass =
                            ServiceofferingMP.GetClass("System.RequestOffering");
                        EnterpriseManagementObject changeRequest = null;
                        foreach (EnterpriseManagementObject OfferingEntity in managementGroup.EntityObjects.GetObjectReader<EnterpriseManagementObject>(mpRequestOfferingClass, ObjectQueryOptions.Default))
                        {
                            if (OfferingEntity.DisplayName == "Create_PVD_RequestOffring")                        
                            {
                                changeRequest = OfferingEntity;
                                
                                changeProjection = new EnterpriseManagementObjectProjection(changeRequest);
                                CreatableEnterpriseManagementRelationshipObject cemrorequestOffering2Workitem =
                                new CreatableEnterpriseManagementRelationshipObject(managementGroup, relworkitem2RequestOffering);
                                //Set the source and target...changeProjecti
                                cemrorequestOffering2Workitem.SetSource(emoSRWorkitem);
                                cemrorequestOffering2Workitem.SetTarget(changeRequest);
                                cemrorequestOffering2Workitem.Commit();
                            }
                        }
                        /*------------------------------------------------------------------------------------------*/
                    }


    Thursday, July 26, 2012 12:11 PM

Answers

  • First, you only need one commit call.

    If _all_ of your activities remain in the "Pending" status, you should check your out-of-the-box Service Manager workflows for any errors. Check the Operations Manager event log to see if there are any errors. Also check the Administration|Workflows|Status view for any errors in any of the "Activity Status Change" workflows.

    And verify that the "System Center Management" service is running.

    • Marked as answer by Ericl Lee Tuesday, August 07, 2012 9:28 AM
    Monday, July 30, 2012 9:41 PM

All replies

  • No Body get the exception?
    Friday, July 27, 2012 9:48 AM
  • That error boils down to this: You can't use "CreatableEnterpriseManagementRelationshipObject" with any "Extension" element. An "Extension" element is NOT to be confused with a class extension..An extension element is part of the Service Manager MP schema..In fact, Request Offerings are defined within an MP's <Extensions> node.

    So, as the error states, "Use EnterpriseManagementObjectProjection for all Extension Element CRUD operations"..('User' is probably just a typo in the error string :) )

    What this means is that you should use the EnterpriseManagementObjectProjection you created earlier (changeProjection) and simply "add" the request offering object to it like this:

    changeProjection.Add(OfferingEntity, relworkitem2RequestOffering.Target);

    You don't need to re-query for the new service reques. In other words, as you're creating your service request (setting the property values, etc), you can simply add the request offering object as a related object. Use changeProjection.Commit() and your whole Service Request will be created, along with the relationship to the specific emoRequestOffering object, at one time.

    Let me know if that's clear or not (I'm not sure how familiar you are with Service Manager's SDK). If it's not clear, I'll go into a little more detail :)

    Friday, July 27, 2012 1:54 PM
  • Hi Aaron,

    I am a new man with Service Mananger's SDK, And very thanks for your help,

    I change my code as you said, but the all the actives of the service Request was always in Pending statues, and my UserInputs cannot set to the runbook active of the service request.

    foreach (EnterpriseManagementObject OfferingEntity in managementGroup.EntityObjects.GetObjectReader<EnterpriseManagementObject>(mpRequestOfferingClass, ObjectQueryOptions.Default))
                        {
                            if (OfferingEntity.DisplayName == "Create_PVD_RequestOffring")                        
                            {
                                changeProjection.Commit();
                                changeProjection.Add(OfferingEntity, relworkitem2RequestOffering.Target);
                                changeProjection.Commit();
                            }
                        }

    Monday, July 30, 2012 2:35 AM
  • First, you only need one commit call.

    If _all_ of your activities remain in the "Pending" status, you should check your out-of-the-box Service Manager workflows for any errors. Check the Operations Manager event log to see if there are any errors. Also check the Administration|Workflows|Status view for any errors in any of the "Activity Status Change" workflows.

    And verify that the "System Center Management" service is running.

    • Marked as answer by Ericl Lee Tuesday, August 07, 2012 9:28 AM
    Monday, July 30, 2012 9:41 PM