Create a computed field for a referenced item

A Sitecore field can reference another Sitecore item, which contains several fields of its own. Sometimes, you may need to retrieve a field from the referenced item to use it in a computed field.

Logic behind Coveo for Sitecore out-of-the-box computed fields | Coveo for Sitecore 5

This can be done using the referencedfieldcomputedfield computed field.

This article provides an example showing how to use the out-of-the-box ReferencedFieldComputedField computed field.


Your content tree contains items of type Flight and items of type Airport.

A Flight contains the following fields:

Field name Field type Example value

Flight Number

Single-Line Text


Departure Airport

Droptree (reference)

Airports/2/3/8/2/0/Amsterdam Airport Schiphol (raw value is actually {23820EE7-87A3-4265-B785-2A1D25C98F72}).

Departure Time


5/23/2014 10:01 PM

Arrival Airport

Droptree (reference)

Airports/9/C/2/F/4/Los Angeles International Airport (raw value is actually {9C2F4988-0951-443C-9526-5DBB5D8D9C02}).

Arrival Time


5/24/2014 12:16 AM


Single-Line Text


An Airport contains the following fields:

Field name Field type Example value

Airport Name

Single-Line Text

Amsterdam Airport Schiphol

Airport Code

Single-Line Text



Single-Line Text



Single-Line Text


Single-Line Text


Time Zone


(+1:00) Central Europe Standard Time








Single-Line Text

Your goal is to populate a departureairportcity field in Flight items by retrieving the content of the City field from a referenced Airport item. In other words, you want to do this:

Logic behind ReferencedFieldComputedField in flight and airport example | Coveo for Sitecore 5

Step 1: Configure the computed field

You must first configure your computed field in the Coveo Search Provider configuration file.

  1. Using a text editor, open the Coveo.SearchProvider.Custom.config file (typically located under App_Config\Include\Coveo).

  2. Locate the fields element with a hint attribute equal to raw:AddComputedIndexField.

  3. Insert the configuration required for your computed field as shown below (that is, just the inner field element).

     <fields hint="raw:AddComputedIndexField">
       <field fieldName="departureairportcity" sourceField="Departure Airport" referencedFieldName="City">Coveo.SearchProvider.ComputedFields.ReferencedFieldComputedField, Coveo.SearchProviderBase</field>

    Here are the available options for your computed field configuration:

    Name Description Example value
    fieldName The name of the new field to create departureairportcity
    sourceField The field containing the referenced item's ID Departure Airport
    referencedFieldName The name of the field on the referenced item City
    returnType Return type of the field The possible values are: Integer, Number, date, datetime, and string.

    This configuration lets you create and index the computed field. If you want to apply special settings to that field (for example, to use it as a facet or to sort results), you also need to add a configuration in the fieldNames section of the configuration file.

Step 2: Rebuild your indexes


To have the computed field created, the related sourceField and referencedFieldName fields must be in the <include> fields list.

To be able to use your newly created computed field, you now need to perform an indexing action. Rebuild your search indexes, or at least re-index the Sitecore items which need the new field.

Step 3: Validate the computed field has been added

Validate that your new field has been added on your items using the Content Browser (platform-ca | platform-eu | platform-au).

In this example, Flight items should now have a field named departureairportcity that contains the city of the departure airport.

Flight departure airport city computed field value in Content Browser | Coveo for Sitecore 5

Step 4: Use the computed field

You can now use your computed field in your layouts and result templates.