--- title: Pass custom parameters to computed fields slug: '2410' canonical_url: https://docs.coveo.com/en/2410/ collection: coveo-for-sitecore-v5 source_format: adoc --- # Pass custom parameters to computed fields Sometimes, you may want to pass custom parameters to a computed field through the configuration. For example, following the [Create a computed date field](https://docs.coveo.com/en/2237/) tutorial, you may want to control when the `archivedate` field is created on items. This tutorial shows how to configure the number of days before an item is archived. ## Prerequisite You have already completed the [Create a computed date field](https://docs.coveo.com/en/2237/) tutorial. ## Step 1: Update the Coveo.Custom project . Using Visual Studio, [open the ArchiveDateField class](https://docs.coveo.com/en/2237#step-1-create-the-required-c-project). . Add a constructor to accept additional XML configuration. [source,c#] ``` private readonly XmlNode m_Configuration; public ArchiveDateField(XmlNode p_Configuration) { m_Configuration = p_Configuration; } ``` . Add a method to parse the configuration XML attributes and return their value. [source,c#] ``` protected string GetConfigurationValue(string p_ConfigurationKey) { string configurationValue = null; if (m_Configuration != null && m_Configuration.Attributes != null) { XmlAttribute configurationAttribute = m_Configuration.Attributes[p_ConfigurationKey]; if (configurationAttribute != null) { configurationValue = configurationAttribute.Value; } } return configurationValue; } ``` . Add a property to retrieve the configuration value formatted as an integer. [source,c#] ``` protected int DaysBeforeArchiving { get { int daysCount; if (!Int32.TryParse(GetConfigurationValue("daysBeforeArchiving"), out daysCount)) { daysCount = 365; // One year by default } return daysCount; } } ``` . Change the `ComputeFieldValue` method to use the `DaysBeforeArchiving` property. [source,c#] ``` /// public object ComputeFieldValue(IIndexable p_Indexable) { SitecoreIndexableItem indexableItem = p_Indexable as SitecoreIndexableItem; if (indexableItem != null) { IIndexableDataField dateField = indexableItem.GetFieldByName(SITECORE_CREATED_FIELD); if (dateField != null) { DateTime itemCreationDate = DateUtil.ParseDateTime(dateField.Value.ToString(), DateTime.MaxValue); return itemCreationDate.AddDays(DaysBeforeArchiving).ToString(COVEO_INDEX_DATE_FORMAT); } } return null; } ``` . Compile your project. . Copy the resulting assembly (`Coveo.Custom.dll`) to the `bin` folder of your Sitecore instance. ## Step 2: Update the computed field configuration Open your `Coveo.SearchProvider.Custom.config` file and add the `daysBeforeArchiving` parameter as an XML attribute. ```xml Coveo.Custom.ArchiveDateField, Coveo.Custom ``` ## Step 3: Rebuild your indexes [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 4: Validate the computed field values Validate the `archivedate` field values 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/)). There should now be a difference of 30 days between the `created` and `archivedate` fields values. ![Screenshot of the item in the Coveo Administration Console highlighting the archivedate and created field values | Coveo](https://docs.coveo.com/en/assets/images/c4sc-v5/35455016.png) > **Warning** > > When running computed field code, check your logs for computed field errors indicating items aren't being indexed. > Implement proper exception handling to avoid these issues. > For example, you might want to stop the process or set a fallback value for a computed field when suitable.