locked
Retrieve contact by partial of the firstname RRS feed

  • Question

  • I try to get list of contacts by partial of first name using ConditionOperator.Like, but it doesn't work? anybody know how to do it?
    Here is my code
    QueryExpression query = new QueryExpression();
                query.EntityName = "contact";
                FilterExpression filter = new FilterExpression();
                filter.Conditions = new ConditionExpression[2];
                filter.FilterOperator = LogicalOperator.And;
                ConditionExpression condition = new ConditionExpression();
                condition.AttributeName = "firstname";
                condition.Operator = ConditionOperator.Like;
                condition.Values = name_val;  //this is string[] of first name with  "bar"
                filter.Conditions[0] = condition;
                 ConditionExpression condition2 = new ConditionExpression();
                condition2.AttributeName = "rate";
                condition2.Operator = ConditionOperator.Like;
                condition2.Values = rate_val;  //this is string[] of rate with  "1"
                filter.Conditions[1] = condition2;
                query.Criteria = filter;
                 query.ColumnSet = new AllColumns();
                 RetrieveMultipleRequest request = new RetrieveMultipleRequest();
                request.Query = query;
                RetrieveMultipleResponse response = (RetrieveMultipleResponse)service.Execute(request);


    in the string[] name_val   if i use "bar", i got no value,  but if i use the "barbara"  then i got value.
    How can i search by partial of string "bar"?   thanks a lot

    Wednesday, July 1, 2009 4:07 PM

Answers

  • You will need to append the wild card char % as part of your search criteria.
    e.g. 
    condition.Values = name_val ";  //this is string[] of first name with  "bar" + "%" -> append % to your search string.

    Hassan.


    Hassan Hussain | http://hassanhussain.wordpress.com/
    • Proposed as answer by Hassan Hussain Wednesday, July 1, 2009 4:11 PM
    • Marked as answer by Yuhe Wednesday, July 1, 2009 5:09 PM
    Wednesday, July 1, 2009 4:11 PM
  • Can you try including a '%' after your 'bar' value and see if that works for you?
    • Marked as answer by Yuhe Wednesday, July 1, 2009 5:10 PM
    Wednesday, July 1, 2009 4:18 PM
    Moderator

All replies

  • You will need to append the wild card char % as part of your search criteria.
    e.g. 
    condition.Values = name_val ";  //this is string[] of first name with  "bar" + "%" -> append % to your search string.

    Hassan.


    Hassan Hussain | http://hassanhussain.wordpress.com/
    • Proposed as answer by Hassan Hussain Wednesday, July 1, 2009 4:11 PM
    • Marked as answer by Yuhe Wednesday, July 1, 2009 5:09 PM
    Wednesday, July 1, 2009 4:11 PM
  • Can you try including a '%' after your 'bar' value and see if that works for you?
    • Marked as answer by Yuhe Wednesday, July 1, 2009 5:10 PM
    Wednesday, July 1, 2009 4:18 PM
    Moderator
  • it works great. thanks a lot

    Wednesday, July 1, 2009 5:09 PM