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" : "70",
"h" : "false",
"hasPrv" : "false",
"ic" : "false"
},
"permanent" : "true",
"classId" : "1538"
},
"getObjects" :
{
"parent" :
{
"id" : "S1!M!62"
},
"filter" :
{
"hideEmptyFolders" : "true",
"classes" :
{
"it" :
{
"k" : "1538"
}
}
},
"arg" :
{
"pattern" :
{
"n" : "false",
"i" : "true",
"ts" : "false",
"ds" : "false",
"isShortcut" : "false"
}
}
}
}
}
}
{
"CreateObjectResult" :
{
"id" :
{
"id" : "S1!M!176176"
},
"object" :
{
"@ds" : "",
"@isShortcut" : "0",
"@isLink" : "0",
"@ver" : "1",
"@hf" : "0",
"i" : "NEWFORM1",
"n" : "NewForm1",
"k" : "176176",
"c" : "1538",
"p" : "62",
"h" : "0",
"hasPrv" : "0",
"ic" : "0",
"obId" :
{
"id" : "S1!M!176176"
}
},
"objects" :
{
"id" :
{
"id" : "S1!M!0"
},
"objects" :
{
"its" :
{
"d" :
{
"@isShortcut" : "0",
"@isLink" : "0",
"@hf" : "0",
"i" : "NEWFORM1",
"n" : "",
"k" : "176176",
"c" : "1538",
"p" : "62",
"h" : "0",
"hasPrv" : "0",
"ic" : "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 update parameters after object creation
getObjects = new GetObjectsOpArg()
{
arg = new GetObjectsArg()
{
//Geted information template
pattern = new OdsPattern()
{
ds = false,
i = true,
isShortcut = false,
n = false,
ts = false
}
},
filter = new OdsFilt()
{
classes = new OdClass[1]
{
//Refresh list of objects with the same class, with which a new object was created
new OdClass(){k = classId},
},
hideEmptyFolders = true
},
//Specify parent object, which contents will be refreshed
parent = new OdId() { id = mb.id + "!" + tParent.k }
}
},
tParent = new OdId()
{
id = mb.id + "!0"
}
};
//Create an object
var result = somClient.CreateObject(tCreateObj);
return result;
}
See also: