1
votes

I have a product template with a multiselect that searches for other product items. For this I use a sitecore query on the source field of the multiselect:

query:fast:/sitecore/content/Home//*[@@templateid='{DEFA2E43-E688-48E5-AE28-1ABA761105E2}']

With this query all the products are show in the select including the current product item.

How can I exclude the product item I'm working on? (exclude self?)

Thanks in advance

2

2 Answers

1
votes

You should be able to use the ExcludeItemsForDisplay where you set the ID of the Item you want to exclude.

See link - http://firebreaksice.com/tame-your-sitecore-treelists/

The complexity will then be to set the ID programmatically via fast-query, i.e. self, unless hardcoding it can meet your requirement.

1
votes

I think the right way to do this is using the getLookupSourceItems pipeline. I've written a blog post about this pipeline here:

http://ctor.io/dynamic-field-sources-with-getlookupsourceitems-pipeline/

Within this pipeline you know the id of the current item with args.Item.ID. You can then rewrite the source dynamically to a query excluding the current item. Something like this (untested):

query:fast:/sitecore/content/Home//*[@@templateid='{DEFA2E43-E688-48E5-AE28-1ABA761105E2}' and @@id != '<current item id>']

The source can be rewritten with args.Source (please see the blog post for more information).