Gravatar for

Question by anwesha, Oct 24, 2016 11:21 AM

Compute a field's value through its references

Hi ,

I am trying to create a computed field for the below scenario.

I have products in my website and some products have a rendering which indirectly point to an FAQ page. By "indeirectly", I mean, the product has a rendering that has a datasource, this datasource has another rendering whiose datasource points to my faq items. I want to create a computed field for all the products to distinguish between products which have FAQs in them and which do not. Please let me know if creating a computed field is the best way to go and how should I proceed with this?

Gravatar for

Comment by anwesha, Oct 25, 2016 12:40 AM

Another approach, my FAQ items have a multilist where my products are directly linked. Can this be used to navigate to the linked product while indexing an FAQ item and add a computed field in the product?

Gravatar for

Comment by François Lachance-Guillemette, Oct 25, 2016 7:58 AM

Yes, the multilist can even be used directly using the computed field documented here:

2 Replies
Gravatar for

Answer by François Lachance-Guillemette, Oct 24, 2016 12:02 PM

Hi @Anwesha

Yes, the computed field is the way to go for referenced items.

Have a look at this documentation page to create your own computed field.


Gravatar for

Answer by Sébastien Belzile, Oct 24, 2016 12:02 PM

Yes, you are on the right track. This is the way it is recommended to do such a thing. OOTB, the Referenced Field computed field is available, but it is not doing exactly what you want. You could decompile the dll to get see how Coveo proceeds. You could use this code as a basis for your code.

The thing you are trying to do is quite complicated and I personally never tried such a thing, but here is some help on the different steps:

You will start with an indexable item. From that, you can get the Sitecore Item:

public override object ComputeFieldValue(IIndexable p_Indexable)
    var item = new ItemWrapper(new IndexableWrapper(p_Indexable));


or if you don't care about Coveo wrappers:

var Item = p_Indexable.Item

Getting the datasource of your Sitecore item is the second step. This can easilly go wrong since an item rendering depends on the device you want to view it with.

I think these are mostly what you will have to do.

Please keep me posted, I'm interested about the details of this implementation + performance.

Ask a question