Gravatar for

Question by dinoforbes, Jan 21, 2016 10:27 PM

SitecoreUtilities.ToCoveoFieldName p_index = null


Using Coveo for Sitecore and MVC.

I have been able to successfully obtain the field name on a number of pages within my site using:

var fieldName = SitecoreUtilities.ToCoveoFieldName("lowecasefieldname");

But for one page in particular I'm getting the error:

Precondition failed: The parameter 'p_Index' must not be null
Parameter name: p_Index

Baffled as to why this is working on other pages and not this page.

I have cshtml markup for the non working page and working page and can't see the difference.

I read another comment suggesting to reference the Iindexable to point to the correct index but not sure how to go about this?

Any help appreciated. Thank you.



1 Reply
Gravatar for

Answer by Jean-François L'Heureux, Jan 22, 2016 9:26 AM

Hi Dino,

In Coveo for Sitecore MVC views, the model contains a helper for the ToCoveoFieldName method. You can call it with:


This helper will automatically resolve the name of the index to use by looking at the Sitecore context current site database. It will try to find the first Sitecore index of the Coveo type that is configured to index that database.

So if the page using your non-working view is from a different Sitecore site configuration and this site uses a database that is not indexed by Coveo, it could be the cause of your issue.

Gravatar for

Comment by dinoforbes, Jan 24, 2016 8:37 PM

Hi Jean-François,

Thank you for your suggestion, I tried your suggestion but the same result. The work around I did was to define the Indexable object for the root item of the master database and then I was able to grab the field name once the indexable object was not null, the reason I believe this is the case as you stated because the current item being checked uses a custom database called 'user' This the content of the 'user' database has been added to the search crawler via the search config but for some reason the current item doesn't reference back to any index

Sample code for my workaround:

var currentDatabaseName = Context.Database.Name;
if (currentDatabaseName != "web") currentDatabaseName = "master";
using (new DatabaseSwitcher(Database.GetDatabase(currentDatabaseName)))
    var rootItem = SitecoreContext.Database.GetRootItem();
    if (rootItem != null)
        facetFilter = new FieldHelper().ToCoveoFieldName(new ItemWrapper(rootItem).ToIndexable(), "userteamgroupfacet");

I then passed this data to the model and therefore able to work around the issue.

Thanks again for your effort and time in answering my questions.

Gravatar for

Comment by Jean-François L'Heureux, Jan 25, 2016 10:27 AM

Glad it works with your workaround. However, this is a bad smell to me. I think your Sitecore sites or indexes configuration have issues that should be fixed to ensure it follows the best practices.

Ask a question