This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - Creating a new ItemType using the IOM

markW - Tuesday, January 30, 2007 6:06 PM:

How do I create a new Item Type through the IOM?  Is this possible?  I can see ways to create instances of existing types, but don’t see how to create the type itself

RobMcAveney - Tuesday, January 30, 2007 6:25 PM:

You use the exact same techniques to create ItemTypes as you do to create instances.  After all, an ItemType is just an instance of the ItemType ItemType (wrap your head around that one!).  Here is some sample method code (server-side, C#):

 
String itemTypeName = "MyItemType";
Innovator inn = this.newInnovator();

// ItemType
Item myItemType = this.newItem("ItemType","add");
myItemType.setProperty("name",itemTypeName);
myItemType.setProperty("label",itemTypeName);

// Properties
Item numberProp = this.newItem("Property","add");
numberProp.setProperty("name","item_number");
numberProp.setProperty("label","Number");
numberProp.setProperty("data_type","string");
numberProp.setProperty("stored_length","32");
numberProp.setProperty("keyed_name_order","1");
numberProp.setProperty("order_by","1");
myItemType.addRelationship(numberProp);

Item nameProp = this.newItem("Property","add");
nameProp.setProperty("name","name");
nameProp.setProperty("label","Name");
nameProp.setProperty("data_type","string");
nameProp.setProperty("stored_length","32");
myItemType.addRelationship(nameProp);

// Permission
Item allowedPerm = this.newItem("Allowed Permission","add");
allowedPerm.setProperty("is_default","1");
Item perm = this.newItem("Permission","add");
perm.setProperty("name",itemTypeName);
perm.setIdentityAccess("World","get","1");
perm.setIdentityAccess("World","update","1");
perm.setIdentityAccess("World","delete","1");
allowedPerm.setRelatedItem(perm);
myItemType.addRelationship(allowedPerm);

// Can Add
Item canAdd = this.newItem("Can Add","add");
canAdd.setProperty("can_add","1");
Item worldIdent = inn.getItemByKeyedName("Identity","World");
canAdd.setRelatedItem(worldIdent);
myItemType.addRelationship(canAdd);

// TOC Access
Item tocAccess = this.newItem("TOC Access","add");
tocAccess.setRelatedItem(worldIdent);
myItemType.addRelationship(tocAccess);

// Apply
Item resultItem = myItemType.apply();
return resultItem;