--- title: Create a computed field for a referenced item slug: '2238' canonical_url: https://docs.coveo.com/en/2238/ collection: coveo-for-sitecore-v5 source_format: adoc --- # 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](https://docs.coveo.com/en/assets/images/c4sc-v5/out-of-the-box-computed-fields.png) This can be done using the [`referencedfieldcomputedfield`](https://docs.coveo.com/en/2623#the-referencedfieldcomputedfield-computed-field) computed field. This article provides an example showing how to use the out-of-the-box `ReferencedFieldComputedField` computed field. ## Scenario 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 | 3836 | Departure Airport | Droptree (reference) | Airports/2/3/8/2/0/Amsterdam Airport Schiphol (raw value is actually \{23820EE7-87A3-4265-B785-2A1D25C98F72}). | Departure Time | Datetime | 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 | Datetime | 5/24/2014 12:16 AM | Price | Single-Line Text | 586 |=== 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 | AMS | City | Single-Line Text | Amsterdam | State | Single-Line Text | | Country | Single-Line Text | Netherlands | Time Zone | Droplink | (+1:00) Central Europe Standard Time | Latitude | Number | 52 | Longitude | Number | 5 | Aliases | 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](https://docs.coveo.com/en/assets/images/c4sc-v5/out-of-the-box-referenced-field.png) ## Step 1: Configure the computed field Configure your computed field in the Coveo Search Provider configuration file. . Using a text editor, open the `Coveo.SearchProvider.Custom.config` file (typically located under `App_Config\Include\Coveo`). . Locate the `fields` element with a `hint` attribute equal to `raw:AddComputedIndexField`. . Insert the configuration required for your computed field as shown below (that is, just the inner `field` element). ```xml Coveo.SearchProvider.ComputedFields.ReferencedFieldComputedField, Coveo.SearchProviderBase ``` 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.
> **Note** > > This configuration lets you create and index the computed field. > 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](https://docs.coveo.com/en/2166/) of the configuration file. ## Step 2: Rebuild your indexes > **Important** > > To have the computed field created, the related `sourceField` and `referencedFieldName` fields must be in [the `` fields list](https://docs.coveo.com/en/2566#fields). To be able to use your newly created computed field, you now need to perform an indexing action. [Rebuild your search indexes](https://docs.coveo.com/en/2426#rebuilding-a-search-index-manually), or at least [re-index the Sitecore items which need the new field](https://docs.coveo.com/en/2426#re-indexing-a-section-of-your-content-tree-in-the-content-editor). ## Step 3: Validate the computed field has been added Validate that your new field has been added on your items using the [**Content Browser**](https://platform.cloud.coveo.com/admin/#/orgid/content/browser/) ([platform-ca](https://platform-ca.cloud.coveo.com/admin/#/orgid/content/browser/) | [platform-eu](https://platform-eu.cloud.coveo.com/admin/#/orgid/content/browser/) | [platform-au](https://platform-au.cloud.coveo.com/admin/#/orgid/content/browser/)). 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](https://docs.coveo.com/en/assets/images/c4sc-v5/out-of-the-box-referenced-field-result.png) ## Step 4: Use the computed field You can now use your computed field in your layouts and [result templates](https://docs.coveo.com/en/2834/).