Gravatar for paldrich@ascedia.com

Question by Paul Aldrich, Jan 17, 2018 11:37 PM

Date field gets added to cloud platform as a String type

I have a computed field used in a facet. It is used by both Sitecore and external sources and should be a Coveo "Date" type. I am trying to get the field to show up in the cloud platform panel as a Date type, but every time I rebuild my Sitecore index it shows up as "String". In my custom config I have:

Field Map

<fieldType fieldName="aopaResultDate" settingType="Coveo.Framework.Configuration.FieldConfiguration, Coveo.Framework" isExternal="true" isSortable="true" type="System.DateTime" returnType="System.Date" />

I have also tried setting returnType to System.DateTime but no difference.

Computed Field

<field fieldName="AOPAResultDate" sourceField="AOPA.Library.Search.CoveoFields.ResultDate, AOPA.Library" returnType="datetime">AOPA.Library.Search.CoveoFields.ResultDate, AOPA.Library</field>

Why does this happen?

1 Reply
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Jan 19, 2018 12:23 AM

The type of a computed index field is determined by a mix of the fieldmap entry (if any) and the computed index field class. In your case, the `AOPA.Library.Search.CoveoFields.ResultDate` class. It must have a ReturnType property with a `get` that returns "datetime" as explained in this article: https://developers.coveo.com/x/agDvAQ

The `ComputeFieldValue` method should return a string formatted with the Coveo index date format "yyyy/MM/dd@HH:mm:ssZ".

The article also mentions that the fieldMap entry should have `type="System.DateTime" returnType="System.DateTime"`. You seem to have `returnType="System.Date"` in yours.

In your computed index field, I am not sure about your `sourceField` attribute value. This seems to be the filly qualified name of a constant or a class property. Are you using reflection in your computed field code to its value? If you are not, this attribute value should be the actual name of a Sitecore field item in one of your templates.

Gravatar for paldrich@ascedia.com

Comment by Paul Aldrich, Jan 19, 2018 3:22 PM

Hi Jeff,

Yes.. this is exactly what I needed to do. I think I kept getting tripped up on the fact that the computed field was technically returning a string, not a datetime, but this did work, the field is now a Date type in the cloud platform. Also, I found conflicting articles on whether to use System.DateTime or System.Date, and realized that I really need to check the CfS or JSUI version on all documents I read!

As for sourceField, I will have to get back to you. Pretty sure I got that from an official Coveo document, but again it could be something from V3 that should be completely different.

Thanks,

Paul

Ask a question