Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving the parent URI of a BluePrinted component based on the URI of a child component

Does anyone know how can I find the URI of a parent Component based on the URI of a shared or localized component in a child publication in SDL Tridion using the Core Service?

like image 390
Kremena Lalova Avatar asked Dec 05 '25 17:12

Kremena Lalova


1 Answers

You can use ComponentData.BluePrintInfo.OwningRepository.IdRef to get the TcmUri of the publication that "owns" that component. This is the first publication "going up" where the component is either created or localized.

Then you can use something like this to get you the component Uri in the right context:

internal string GetUriInBlueprintContext(string itemId, string publicationId)
{
    if (TcmUri.UriNull == itemId)
        return null;
    TcmUri itemUri = new TcmUri(itemId);
    TcmUri publicationUri = new TcmUri(publicationId);
    TcmUri inContext = new TcmUri(itemUri.ItemId, itemUri.ItemType, publicationUri.ItemId);
    return inContext.ToString();
}

The TcmUri class is part of the Tridion.Common.dll which you can reference from your project too.

like image 101
Nuno Linhares Avatar answered Dec 08 '25 10:12

Nuno Linhares



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!