The example of using the SaveObjectAs operation to create a copy of repository object. The copied object moniker, the description of the parent object, in which the copy is created, and parameters for creating the copy are sent in the request. The response contains the updated list of objects of the folder, in which the copy was created.
The JSON request contains moniker of the object, for which the copy must be created, and parameters for creating the copy. The JSON response contains the updated list of objects of the folder, in which the copy was created.
{
"SaveObjectAs" :
{
"tObject" :
{
"id" : "S1!M!176019"
},
"tArg" :
{
"destination" :
{
"operation" : "CreateNew",
"create" :
{
"name" : "Regular report(Copy)",
"id" : "REPORT_Copy",
"parent" :
{
"@isShortcut" : "false",
"@isLink" : "false",
"@hf" : "false",
"i" : "WORK",
"n" : "Work",
"k" : "62",
"c" : "0",
"p" : "70",
"h" : "false",
"hasPrv" : "false",
"ic" : "false"
}
},
"withData" : "true",
"autoGenerateName" : "true"
},
"getObjects" :
{
"parent" :
{
"id" : "S1!M!62"
}
}
}
}
}
{
"SaveObjectAsResult" :
{
"object" :
{
"@ds" : "",
"@isShortcut" : "0",
"@isLink" : "0",
"@ver" : "2",
"@hf" : "0",
"i" : "REPORT_COPY",
"n" : "Regular report(Copy)",
"k" : "176178",
"c" : "2562",
"p" : "62",
"h" : "0",
"hasPrv" : "0",
"ic" : "0",
"obId" :
{
"id" : "S1!M!176178"
}
},
"objects" :
{
"id" :
{
"id" : "S1!M!176019"
},
"objects" :
{
"its" :
{
"d" :
{
"@isShortcut" : "0",
"@isLink" : "0",
"@hf" : "0",
"i" : "REPORT_COPY",
"n" : "Regular report(Copy)",
"k" : "176178",
"c" : "2562",
"p" : "62",
"h" : "0",
"hasPrv" : "0",
"ic" : "0"
}
}
}
}
}
}
The CreateCopyObj function specified below creates an object copy. The identifier of the copied object and also the parent object, in which the copy is created, are sent with the objId and parentId input parameters. The example uses the FindObjectById function, which code is given in the Getting Object Description by Its Identifier example. The result of the operation is the result of the function.
public static SaveObjectAsResult CreateCopyObj(MbId mb, string objId, string parentId)
{
var somClient = new SomPortTypeClient(); //Proxy object for operation execution
var tObj = FindObjectById(mb, objId);
var tParent = FindObjectById(mb, parentId);
//Operation execution parameters
var tSave = new SaveObjectAs()
{
tArg = new SaveObjectAsArg()
{
destination = new ObjectCopyInfo()
{
//Action - create copy
operation = ObjectCopyOperation.CreateNew,
create = new ObjectCreateBaseInfo()
{
id = tObj.i + "_Copy",
name = tObj.n + "(Copy)",
parent = tParent
},
withData = true
},
getObjects = new GetObjectsOpArg()
{
parent = new OdId() { id = mb.id + "!" + tParent.k }
}
},
tObject = new OdId()
{
id = mb.id + "!" + tObj.k
}
};
//Create copy
var result = somClient.SaveObjectAs(tSave);
return result;
}
See also: