tags:

views:

133

answers:

2

I need to search for accounts in Microsoft CRM, using a wildcard search to get a "contains" search for the user's input. So if the user enters "ABC", I use ConditionOperator.Like and the value "%ABC%".

My question is, how would I search for a customer name that contains a percentage sign, such as "100% Great llc"? I can't find a way to escape the %.

+1  A: 

Try using square blocks for special characters, for instance like [%]. So the condition would be: 100[%] Great llc or %100[%] Great llc%.

--EDIT--

This is in response to your comment.

Try utilizing the ConditionExpression, something like following:

//1. Condition expression.
ConditionExpression nameCondition= new ConditionExpression();
            nameCondition.AttributeName = "AccountName";
            nameCondition.Operator = ConditionOperator.Like;
            nameCondition.Values = new string[] { "%100[%] Great llc%" };

//2. Create filter expression
FilterExpression nameFilter = new FilterExpression();
nameFilter.Conditions = new ConditionExpression[] { nameCondition };

//3. Provide columns
ColumnSet resultSetColumns = new ColumnSet();
            resultSetColumns.Attributes = new string[] { "name", "address" };

//4. Prepare query expression
QueryExpression qryExpression = new QueryExpression();
            qryExpression.Criteria = nameFilter;
            qryExpression.ColumnSet = resultSetColumns;

//5. Set the table to query.
qryExpression.EntityName = EntityName.account.ToString();

//6. BusinessEntityCollection accountsResultSet = service.RetrieveMultiple(qryExpression);

Though I have played alot with CRM, but never came across special characters scenario. Let me know your findings. This article has some revelations.

KMan
Doesn't seem to work. It doesn't return accounts containing a %.
Geoff Maybache
@Geoff: Did you try tsql? For instance, try `'%100\%%' ESCAPE '\'?` or `'%100\% Great llc%' ESCAPE '\'?`
KMan
Unfortunately I can't. Coding standards force me to use the CRM SDK and no direct SQL access :(
Geoff Maybache
@Geoff: Please see my edit in response to your comment.
KMan
+1  A: 

Sounds like you're looking for a SQL-based approach so I'm not sure if this helps.

One way I know is through the user interface with an asterisk *

So if you want to find all of the accounts that have a % sign just type in *% into the account search.

Paul