Below is the example of using the CreateObject operation to create a repository object. The request contains the basic information required to create an object: identifier, name, object class identifier and description of the parent object. Also, the created object is indicated as permanent that enables the user to save the object right after it is created. The specified information is used to update the list of objects included in the parent object after creating a new object. The response contains description and the moniker of the created object, and the updated list of objects included in the parent object.
{ "CreateObject" : { "tParent" : { "id" : "S1!M!0" }, "tArg" : { "info" : { "name" : "NewForm1", "id" : "NewForm1", "parent" : { "@isShortcut" : "false", "@isLink" : "false", "@hf" : "false", "i" : "WORK", "n" : "Work", "k" : "62", "c" : "0", "p" : "4294967295", "h" : "false" }, "permanent" : "true", "classId" : "1538" }, "getObjects" : { "parent" : { "id" : "S1!M!62" }, "filter" : { "hideEmptyFolders" : "true", "classes" : { "it" : { "k" : "1538" } } }, "arg" : { "pattern" : { "sd" : "false", "n" : "false", "i" : "true", "ts" : "false", "ds" : "false", "isShortcut" : "false" } } } } } }
{ "CreateObjectResult" : { "id" : { "id" : "S1!M!8081" }, "object" : { "@isShortcut" : "0", "@isLink" : "0", "i" : "NEWFORM1", "n" : "NewForm1", "k" : "8081", "c" : "1538", "p" : "62", "h" : "0", "obId" : { "id" : "S1!M!8081" } }, "objects" : { "id" : { "id" : "S1!M!0" }, "objects" : { "its" : { "d" : { "@isLink" : "0", "@hf" : "0", "i" : "NEWFORM1", "n" : "", "k" : "8081", "c" : "1538", "p" : "4294967295", "h" : "0" } } } } } }
The specified CreateObject function creates a repository object within the specified parent object. The repository connection moniker, the identifier of the parent and the created objects and also the identifier of the created object class are sent as input parameters. The result of the function is the result of the operation.
The example uses the FindObjectById function, which code is given in the Getting Object Description by Its Identifier example.
public static CreateObjectResult CreateObject(MbId mb, string parent, string id, ulong classId) { var somClient = new SomPortTypeClient(); //Proxy object for operation execution //Operation execution parameters var tParent = FindObjectById(mb, parent);
var tCreateObj = new CreateObject() { tArg = new CreateObjectArg() { //Information about created object info = new ObjectCreateInfo() { classId = classId, id = id, name = id
parent = tParent, permanent = true }, //Repository refresh parameters after object creation getObjects = new GetObjectsOpArg() { arg = new GetObjectsArg() { //Extracted information pattern pattern = new OdsPattern()
{ ds = false, i = true, isShortcut = false, n = false, sd = false, ts = false } }, filter = new OdsFilt()
{ classes = new OdClass[1] { //Refresh list of objects with the same class, with which new object is created new OdClass(){k = classId}, }, hideEmptyFolders = true }, //Specufy parent object, which contents is refreshed parent = new OdId() { id = mb.id + "!" + tParent.k }
} }, tParent = new OdId() { id = mb.id + "!0" } }; //Object creation var result = somClient.CreateObject(tCreateObj); return result; }
See also: