Tip #1270: Table or view is not full-text indexed

Today’s tip is from Marius Agur Hagelund “Viking” Lind (actually, I’m confused, perhaps it’s Marius “Viking” Agur Hagelund Lind?). Got a tip of your own? Send it to jar@crmtipoftheday.com.

Cannot use CONTAINS or FREETEXT predicate on table or indexed view because it is not full-text indexed

Mean SQL Server

If you’ve ever got this error message it’s probably because you tried searching using the SDK using the contains keyword on a field which isn’t full-text indexed.

For me it was searching for systemusers:

nameSearch.Criteria.AddCondition("firstname",
   ConditionOperator.Contains, 
   searchString);

I got the following nice error message in return, which puzzled me at first

Cannot use a CONTAINS or FREETEXT predicate on table
or indexed view 'SystemUserBase' because it is not full-text indexed.

I tried checking in the system, and found that I could search for names there when I used wildcard characters, and then it dawned on me that all these years of autocomplete, intellisense and helpers have made my lazy and dumb. Using wildcards is not the same as using CONTAINS, which is very obvious if you take a SQL Server 101 course found anywhere, so the solution was as easy as this:

nameSearch.Criteria.AddCondition("firstname",
   ConditionOperator.Like,
   $"%{searchString}%");

But what about the web api? Well, turns out they removed the Microsoft.Dynamics.Crm.Contains action and only use the Contains keyword (api/data/v9.1/systemusers?$contains(firstname, ‘mike d’). That is, unless you want to perform a full-text search in knowledge base articles:

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/fulltextsearchknowledgearticle?view=dynamics-ce-odata-9

So lesson learned: Stop being a dinosaur and start using the web api.

Viking out.

Cover photo by unsplash-logoDaiga Ellaby

One thought on “Tip #1270: Table or view is not full-text indexed

  1. […] Table or view is not full-text indexed […]

Leave a Reply

Your email address will not be published. Required fields are marked *