Gravatar for lautaro.bonetto@gmail.com

Question by Lautaro Bonetto, Sep 3, 2014 4:47 PM

How can I get a custom field on a pre-conversion script?

Hi everyone, I need to create a pre-conversion script to skip out-of-date promotions on the Coveo index. Coveo is taking this data on a field called @promotionenddate. Also, I builded this JScript script, but it's not working.

This script works perfect:

var fieldName = PreConversion.GetParameter("FilterFieldName")
PreConversion.Trace("---> " + fieldName , 1);

But, when I add this new line stop working.

var fieldName = PreConversion.GetParameter("FilterFieldName")
var value = DocumentInfo.GetFieldValue("promotionenddate");
PreConversion.Trace("---> " + fieldName , 1);

I'm not sure, but looks like something is wrong when I'm trying to get the value from the field. I'm using exactly the line of code on other pre-conversion script, but with other field and it's working fine. This other field is an script with the name "archived". Same field configurations. So, the difference is just the name.

I've checked the indexed data, and they have data on this field. They have a script like this "9/2/2014 12:00:00 AM".

promotionenddate field

Please, can someone help to understand where is the issue?

Thanks Lautaro

Gravatar for cbolduc@coveo.com

Comment by Carl Bolduc, Sep 3, 2014 5:04 PM

What is the MetaData Name of the field @promotionenddate? You can get that information if you reach Configuration->Fields->Your Field Set->Custom Fields->@promotionenddate in the Coveo Administration Tool.

Gravatar for lautaro.bonetto@gmail.com

Comment by Lautaro Bonetto, Sep 3, 2014 5:08 PM

The Metadata Name is "Promotion End Date". It's because I'm taking this data from a field from Sitecore.

http://s4.postimg.org/hlgxcrvml/PreConversionIssue_2.jpg

1 Reply
Gravatar for cbolduc@coveo.com

Answer by Carl Bolduc, Sep 3, 2014 5:12 PM

MetaData are mapped into Coveo fields. At Pre and Post Conversion, only the MetaData values are available. Therefore, you must pass the MetaData name to the GetFieldValue method.

Assuming promotionenddate is the name of the MetaData and not only the name of the field, this will work:

var value = DocumentInfo.GetFieldValue("promotionenddate");
PreConversion.Trace("---> " + value , 1);
Gravatar for lautaro.bonetto@gmail.com

Comment by Lautaro Bonetto, Sep 3, 2014 5:14 PM

Thanks Carl! I put the Metadata Name as a parameter and everything start working.

var value = DocumentInfo.GetFieldValue("Promotion End Date");

Ask a question