Creating an Object within Specified Parent Object

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.

The C# example uses the FindObjectById function, which code is given in the Getting Object Description by Its Identifier example.

SOAP request:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<CreateObject xmlns="http://www.fsight.ru/PP.SOM.Som">
<tParent xmlns="">
  <id>FNDKOLJACBNNFOAEDCEENEKPOGMMOOGEBLEIHFKEJOFOFMNJ!M!0</id>
  </tParent>
<tArg xmlns="">
<info>
  <name>NewForm1</name>
  <id>NewForm1</id>
<parent isShortcut="false" isLink="false" hf="false">
  <i>WORK</i>
  <n>Work</n>
  <k>62</k>
  <c>0</c>
  <p>70</p>
  <h>false</h>
  <hasPrv>false</hasPrv>
  <ic>false</ic>
  </parent>
  <permanent>true</permanent>
  <classId>1538</classId>
  </info>
<getObjects>
<parent>
  <id>FNDKOLJACBNNFOAEDCEENEKPOGMMOOGEBLEIHFKEJOFOFMNJ!M!62</id>
  </parent>
<filter>
  <hideEmptyFolders>true</hideEmptyFolders>
<classes>
<it>
  <k>1538</k>
  </it>
  </classes>
  </filter>
<arg>
<pattern>
  <n>false</n>
  <i>true</i>
  <ts>false</ts>
  <ds>false</ds>
  <isShortcut>false</isShortcut>
  </pattern>
  </arg>
  </getObjects>
  </tArg>
  </CreateObject>
  </s:Body>
  </s:Envelope>

SOAP response:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<CreateObjectResult xmlns="http://www.fsight.ru/PP.SOM.Som" xmlns:q1="http://www.fsight.ru/PP.SOM.Som" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<id xmlns="">
  <id>FNDKOLJACBNNFOAEDCEENEKPOGMMOOGEBLEIHFKEJOFOFMNJ!M!305000</id>
  </id>
<object xmlns="" ds="" isShortcut="0" isLink="0" ver="1" hf="0">
  <i>NEWFORM1</i>
  <n>NewForm1</n>
  <k>305000</k>
  <c>1538</c>
  <p>62</p>
  <h>0</h>
  <hasPrv>0</hasPrv>
  <ic>0</ic>
  <trackElementDependents>0</trackElementDependents>
<obId>
  <id>FNDKOLJACBNNFOAEDCEENEKPOGMMOOGEBLEIHFKEJOFOFMNJ!M!305000</id>
  </obId>
  </object>
<objects xmlns="">
<id>
  <id>FNDKOLJACBNNFOAEDCEENEKPOGMMOOGEBLEIHFKEJOFOFMNJ!M!0</id>
  </id>
<objects>
<its>
<d isShortcut="0" isLink="0" hf="0">
  <i>NEWFORM1</i>
  <n />
  <k>305000</k>
  <c>1538</c>
  <p>62</p>
  <h>0</h>
  <hasPrv>0</hasPrv>
  <ic>0</ic>
  </d>
  </its>
  </objects>
  </objects>
  </CreateObjectResult>
  </soapenv:Body>
  </soapenv:Envelope>

JSON request:

{
"CreateObject" :
{
"tParent" :
{
"id" : "FNDKOLJACBNNFOAEDCEENEKPOGMMOOGEBLEIHFKEJOFOFMNJ!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" : "FNDKOLJACBNNFOAEDCEENEKPOGMMOOGEBLEIHFKEJOFOFMNJ!M!62"
},
"filter" :
{
"hideEmptyFolders" : "true",
"classes" :
{
"it" :
{
"k" : "1538"
}
}
},
"arg" :
{
"pattern" :
{
"n" : "false",
"i" : "true",
"ts" : "false",
"ds" : "false",
"isShortcut" : "false"
}
}
}
}
}
}

JSON response:

{
"CreateObjectResult" :
{
"id" :
{
"id" : "FNDKOLJACBNNFOAEDCEENEKPOGMMOOGEBLEIHFKEJOFOFMNJ!M!305000"
},
"object" :
{
"@ds" : "",
"@isShortcut" : "0",
"@isLink" : "0",
"@ver" : "1",
"@hf" : "0",
"i" : "NEWFORM1",
"n" : "NewForm1",
"k" : "305000",
"c" : "1538",
"p" : "62",
"h" : "0",
"hasPrv" : "0",
"ic" : "0",
"trackElementDependents" : "0",
"obId" :
{
"id" : "FNDKOLJACBNNFOAEDCEENEKPOGMMOOGEBLEIHFKEJOFOFMNJ!M!305000"
}
},
"objects" :
{
"id" :
{
"id" : "FNDKOLJACBNNFOAEDCEENEKPOGMMOOGEBLEIHFKEJOFOFMNJ!M!0"
},
"objects" :
{
"its" :
{
"d" :
{
"@isShortcut" : "0",
"@isLink" : "0",
"@hf" : "0",
"i" : "NEWFORM1",
"n" : "",
"k" : "305000",
"c" : "1538",
"p" : "62",
"h" : "0",
"hasPrv" : "0",
"ic" : "0"
}
}
}
}
}
}
public static CreateObjectResult CreateObject(MbId mb, string parent, string id, uint 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()
{
//Obtained information pattern
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:

CreateObject: Operation