7

I would like to see if a Component is the parent or a copy of the parent using the Tridion JavaScript Framework (Anguilla).

var item = $models.getItem(selection.getItem(0));

if (item.getItemType() == $const.ItemType.COMPONENT) {    }

I have a Component but don't see how I can find out information about being the master parent or a child of the parent.

1 Answer 1

6

On your item, you can call item.getOwningPublicationId() which will return you the URI of its owning Publication, if this is the same as the Publication of which you requested the item (the first part of the TCM URI from item.getId()), then the item is created in this Publication, else you have its parent (note, this could be a parent Publication in which the item is localized).

This and some other properties of the item will be undefined if the item is not fully loaded, so always make sure you load the items like this for example:

var item = $models.getItem(selection.getItem(0));
if (item) {
    // define onload delegate method
    var onItemLoaded = function Namespace$_method$_onItemLoaded() {
        $evt.removeEventHandler(item, "load", onItemLoaded);

        // continue your code here
        var owningPubUri = item.getOwningPublicationId();
    };

    // register onload event for this item
    $evt.addEventHandler(item, "load", onItemLoaded);

    // call to load the item
    item.load(item.isLoaded(true), $const.OpenMode.VIEW);
}

Another option you have is to inspect the item XML, you can get this through item.getXml() or item.getXmlDocument(), but again here the item needs to be fully loaded.

2
  • Hi Bart, getOwningPublicationId return undefined; var item = $models.getItem(selection.getItem(0)); var owningPubUri = item.getOwningPublicationId(); console.log("item: ", item); console.log("owningPubUri: ", owningPubUri); Result: item: Tridion.ContentManager.Component {prototypeMembers: Object, interfaces: Object, properties: Object, addInterface: function, upgradeToType: function…} Dashboard_v6.1.0.55920.7_.aspx?mode=js:472 owningPubUri: undefined
    – user219
    Commented Sep 4, 2013 at 11:25
  • @jarnohenneman yes, please read the second part of my answer and make sure you load the item before requesting methods like getOwningPublicationId(), see also my code example on how to correctly use it. Commented Sep 4, 2013 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.