Skip to content

Error “Cannot process extension elements as EnterpriseManagementObject”

Error “Cannot process extension elements as EnterpriseManagementObject” published on No Comments on Error “Cannot process extension elements as EnterpriseManagementObject”

When you create your own code to create new objects inside SCSM then soon or not but you’l get next exception just after calling Commt() method:

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

What is that and why you get this?

Let’s assume that you want to create new Service Request like that:

ManagementPack serviceRequestMP = emg.ManagementPacks.GetManagementPack("System.WorkItem.ServiceRequest.Library", "31bf3856ad364e35", null);
ManagementPackClass serviceRequestClass = serviceRequestMP.GetClass("System.WorkItem.ServiceRequest");
CreatableEnterpriseManagementObject serviceRequest = new CreatableEnterpriseManagementObject(emg, serviceRequestClass);
serviceRequest[serviceRequestClass, "Title"].Value = "My new SR";
serviceRequest.Commit();

If try to run this code you’l get exception as above. The first part of exception message is self-described. The second can confuse someone. First of all “CRUD” look like typos. It’s not really. CRUD is abbreviation from “Create Read Update Delete” words. After that the second part is must be clear too.

Now how to avoid that. The easiest way to avoid exception is using EnterpriseManagementObjectProjection constructor with object as parameter like this:

ManagementPack serviceRequestMP = emg.ManagementPacks.GetManagementPack("System.WorkItem.ServiceRequest.Library", "31bf3856ad364e35", null);
ManagementPackClass serviceRequestClass = serviceRequestMP.GetClass("System.WorkItem.ServiceRequest");
CreatableEnterpriseManagementObject serviceRequest = new CreatableEnterpriseManagementObject(emg, serviceRequestClass);
serviceRequest[serviceRequestClass, "Title"].Value = "My new SR";

EnterpriseManagementObjectProjection proj = new EnterpriseManagementObjectProjection(serviceRequest);
proj.Commit();

Also you can use another constructor to do that:

ManagementPack serviceRequestMP = emg.ManagementPacks.GetManagementPack("System.WorkItem.ServiceRequest.Library", "31bf3856ad364e35", null);
ManagementPackClass serviceRequestClass = serviceRequestMP.GetClass("System.WorkItem.ServiceRequest");

EnterpriseManagementObjectProjection proj = new EnterpriseManagementObjectProjection(emg, serviceRequestClass);
proj.Object[serviceRequestClass, "Title"].Value = "My new SR";
proj.Commit();

To add new relationship you can use any implementation of Add method:

ManagementPack serviceRequestMP = emg.ManagementPacks.GetManagementPack("System.WorkItem.ServiceRequest.Library", "31bf3856ad364e35", null);
ManagementPackClass serviceRequestClass = serviceRequestMP.GetClass("System.WorkItem.ServiceRequest");

EnterpriseManagementObjectProjection proj = new EnterpriseManagementObjectProjection(emg, serviceRequestClass);
proj.Object[serviceRequestClass, "Title"].Value = "My new SR";
// objCurrentUser is EnterpriesManagementObject
// relAssignedTo is ManagementPackRelationship
proj.Add(objCurrentUser, relAssignedTo)
proj.Commit();

Good example of how to use EnterpriseManagementObjectProjection you can find here (thanks to Aaron).

Another useful links:

Creating (or Editing) an Object From a Template Programmatically
Using the SDK to Create and Edit Objects and Relationships Using Type Projections

Share

Leave a Reply

Primary Sidebar

%d bloggers like this: