web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Query expression

(0) ShareShare
ReportReport
Posted on by 55

write code for the Query expression which will retrieve the two attributes from entity let say "Account".

*This post is locked for comments

I have the same question (0)
  • Verified answer
    PranavShroti Profile Picture
    4,510 on at

    you can use the below code:

    QueryExpression query = new QueryExpression

    {

    EntityName = "account",

    ColumnSet = new ColumnSet("Col1", "Col2"),

    Criteria = new FilterExpression

    {

    Conditions = { new ConditionExpression { AttributeName = "address1_city", Operator = ConditionOperator.NotNull } }

    }

    };

    EntityCollection eCollection = service.RetrieveMultiple(query);

    if (eCollection .Entities.Count > 0)    //Check for result count

    {

    foreach (var item in eCollection .Entities)

    {

    if (item.Attributes["Col1"].ToString() == "Chennai")  //Condition here

    {

    item.Attributes["Col2"] = "India";

    service.Update(item);

    }

    }

    }

    Regards

    Pranav

    If found useful, please mark the answer as verified

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Please refer below -

    msdn.microsoft.com/.../gg328149.aspx

    msdn.microsoft.com/.../gg327917.aspx

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    You can try the below code-

    ==============

    public void CheckQE()

           {

               ClientCredentials _credential = new ClientCredentials();

               _credential.UserName.UserName = "user@testcrm.onmicrosoft.com";

               _credential.UserName.Password = "password";

               var _organizationURI = "testcrm.crm6.dynamics.com/.../Organization.svc";

               using (service = new OrganizationServiceProxy(new Uri(_organizationURI), null, _credential, null))

               {

                   QueryExpression qe = new QueryExpression();

                   qe.EntityName = "account";

                   qe.ColumnSet = new ColumnSet();

                   qe.ColumnSet.Columns.Add("name");

                   qe.ColumnSet.Columns.Add("accountnumber");

                   var results = service.RetrieveMultiple(qe);

                   foreach (Entity act in results.Entities)

                   {

                       if (act.Contains("name"))

                       {

                           Console.WriteLine("Account Name:" + act["name"]);

                       }

                       if (act.Contains("accountnumber"))

                       {

                           Console.WriteLine("Account Number:" + act["accountnumber"]);

                       }

                   }

               }

           }

    ===============

  • Verified answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hello,

    In addition to that did you check SDK ??, it has sample codes which should help you. If not done yet download latest CRM 2016 SDK.

  • Verified answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi Srinivasareddy Sagili,

    You can use the code below.

    QueryExpression query = new QueryExpression
    {
    EntityName = "account",
    ColumnSet = new ColumnSet("name","accountnumber"),
    Criteria = new FilterExpression
    {
    Conditions =
    {
    new ConditionExpression
    {
    AttributeName = "accountid",
    Operator = ConditionOperator.Equal,
    Values = { new Guid("xxxx-xxx-xxxx-xxxxx-xxxx") }
    }
    }
    }
    };
    orgService.RetrieveMultiple(query);

    See: https://arunpotti.wordpress.com/2014/12/11/retrieve-records-using-query-expression-c-sdk-in-crm/

    Hope this helps.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans