Content Hub Tip #35: Hidden gem when filtering

 

Content Hub Tips logo

We all know that feeling that we miss something in a product. If it's not there, we simply can't find it. It's good to know that Sitecore provides us with more than documentation. It's good to know that Sitecore Support is there to help us out.

One of the things I really missed in Content Hub, is filtering out entities that already have a relation with the parent entity. For example, a Product entity that has related assets. If you search for assets to link to, you don't want to show the already linked assets. I always thought this was a shortcoming of the product and that it simply wasn't possible.

For example, we have Nike Air Jordan 1 - True Blue shoes in our product catalogue. We already have a left and right image of the shoes. 

Product example
Used images are trademarks of Nike

If we open the linked asset search, we see the assets that are already linked to the product. Which is not very helpful for the end user.

Product example linked assets
Used images are trademarks of Nike

Luckily for me, someone asked me the question on Slack and I decided to put the Support team to the test. You can imagine my surprise that they came up with an actual answer, saying it's possible. Apparently, there is a filter operator named Missing. Which is what we need to solve the issue.

So how does it work?
For this example, I'm going to modify the product details page. You can find this page under Home > Products > Products > Product detail. 

Product details page configuration
If we open the Add existing assets search, we see the following filter. The first filter in the list is a definition filter. It ensures that we search only displays entities of entity definition M.Asset. Next to that, we filter the assets that are either uploaded via the Asset Create page or manually uploaded on a Product detail page. This is done via the Content Repository relation.

Product details - Add existing assets search

The only thing that is missing is a relation filter between M.PCM.Product and M.Asset with a missing operator. This can be read as, if the asset hasn't been linked to the product, it's allowed to be shown. Combine this with the other filters and we have the situation that we want. The newly filter to be added is configured as follows:

Filter missing relation configuration
The actual configuration depends on the entity definitions that you've selected of course. These most likely will be different for you. Be sure to save the filter and the page. Refresh the Product details and voila, the pop-up is now filtered and doesn't show already linked assets any more.

Filtered linked assets
Used images are trademarks of Nike

Until next time!