Friday, April 27, 2012

How to set the same content on multiple objects

There are situations when you want to set the same content on more objects. If you use the standard approach of setting content on each object, because a content object (dmr_content) will be created per each document object. On one hand it's a bit of redundancy, isn't it? On the other - if you change one content, the other (related) contents won't be updated.
That's why it's more convenient to set (link) one content object to multiple document objects, action known as binding.
You can bind an existing content of an object to another object via DFC code or an API call.

API> bindfile,c,[TARGET_ID],0,[SRC_ID],0

where:
TARGET_ID - the id of the sysobject you are binding to
0 - the position of the content in the object (0 is the first/primary content)
SRC_ID - the id of the source object that the content is assigned (linked) to
DFC code:
IDfId childId = new DfId("[target id]");
IDfId parentId = new DfId("[source id]");
IDfSysObject sysobject = session.getObject(childId);
sysobject.bindFile(0, parentId, 0);
sysobject.save();

No comments:

Post a Comment