0

I'm using SDL Web 8.5 While rendering a Component Presentation from child Publication, I need to validate the presence of the Component in it's top Parent Publication. It might happen that it's been created in level 2 parent Publication and localized in child or locally created in child Publication.

I do not receive a NULL object while creating a Component object with parent publication which does not exist but receive exception while accessing it's properties at runtime.

var ParentObject = this.Engine.GetObject<Component>(new TcmUri(repositoryChildObject.Id.ItemId,
repositoryChildObject.Id.ItemType, this.ParentPublication.Id.ItemId));

The globalObject is not NULL although such a Component does not exist in parent Publication. globalObject.Title throws an error

Component does not exist

2

You can use IsExistingObject to verify if the object exists, this google search shows some examples of using it: https://www.google.com/search?q=session+isexistingobject+tridion

Something along these lines:

if(this.Engine.GetSession().IsExistingObject(tcmUri)) { // object exists}

You'd need to make sure the Tcm Uri to the object you're checking is changed to reflect the actual publication.

1
  • Thanks Nuno! It works. :) – Suman Daripa Nov 9 '20 at 6:36
1

It depends what you need, if indeed to check whether an item exists, then it's Nuno's answer. Otherwise...

I need to validate the presence of the Component in it's top Parent Publication

You have a property on a Component (and other Repository Objects) which will give you the Item in the context of what you call the "top Parent Publication", see: RepositoryLocalObject.PrimaryBluePrintParentItem.

PrimaryBluePrintParentItem will always give you the Item from the Publication where it's created no matter how many layers it's localized in between your context Publication and it's origin.

1
  • RepositoryLocalObject.PrimaryBluePrintParentItem.ContextRepository does not work for me when the content is localized in immediate parent publication. – Suman Daripa Nov 9 '20 at 6:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.