locked
Search functionality by all the CRM fields in c#.net for CRM 2011. RRS feed

  • Question

  • Hello,

    I want to implement Search functionality in one sample asp.net application form.

    In that i am taking one Entity. let say "new_offered". I am searching by its ID using below code

    QueryExpression query = new QueryExpression
    {
        EntityName = "new_offered",
        ColumnSet = new ColumnSet(true),
        Criteria = new FilterExpression
        {
            FilterOperator = LogicalOperator.And,
            Conditions =
                       {
                       new ConditionExpression
                        {
                            AttributeName = "new_id",
                            Operator= ConditionOperator.Equal,
                            Values = {txtSearch.Text}
                        }
                       }
        },
    };

    But i want to enter anything in 'txtSearch' textbox and want to search through all the fields of this "new_offered" Entity.

    How can i do that ?


    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Wednesday, December 4, 2013 6:15 AM

All replies

  • Hello,

    you can compare for all fields using using Or operator


    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Wednesday, December 4, 2013 8:35 AM
    Moderator
  • Hello Mahender,

    Thanks for your response.

    You mean to say like below.. Right ?

    QueryExpression query = new QueryExpression
    {
        EntityName = "new_offered",
        ColumnSet = new ColumnSet(true),
        Criteria = new FilterExpression
        {
            FilterOperator = LogicalOperator.Or,
            Conditions =
                       {
                        new ConditionExpression
                        {
                            AttributeName = "new_id",
                            Operator= ConditionOperator.Equal,
                            Values = {txtSearch.Text}
                        },
    					new ConditionExpression
                        {
                            AttributeName = "new_branch",
                            Operator= ConditionOperator.Equal,
                            Values = {txtSearch.Text}
                        },
    					new ConditionExpression
                        {
                            AttributeName = "new_state",
                            Operator= ConditionOperator.Equal,
                            Values = {txtSearch.Text}
                        }
                       }
        },
    };

    But here, "new_branch" and "new_state" fields are Option set/Lookup type fields, and when this query executes ,error gives like it is expected Int32 value. But in this case we can only search by only one textbox.

    How can i do that ?


    Wednesday, December 4, 2013 8:41 AM
  • Hello,

    You need to Randall all these cases in your code, you use existing helper classes in SDK.


    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Wednesday, December 4, 2013 9:30 AM
    Moderator
  • Can you describe more ?

    I could understand that but can you show that how can i do in my code ? Means how will i match Option Set/Lookup fields with my textbox ?

    That would be great help.

    Wednesday, December 4, 2013 9:36 AM