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)

Queryexpression retrieve

(0) ShareShare
ReportReport
Posted on by 195

i wanna create or update values of country based on the values of city in the account entity.can somebody guide me to obtain this.i want to retrieve city .for example city=chennai.  i wanna update india(manually i want to update).so i wanna retrieve city and update country. both city and country is in account entity

*This post is locked for comments

I have the same question (0)
  • joman Profile Picture
    617 on at

    If you describe more clearly, what do you need, i'll help you.

    As I understand, you need to write Queryexpression to retrieve something. So Describe, What do you want to query and what conditions do you need.

    How city and country links with each other?

  • Gopalan Bhuvanesh Profile Picture
    11,401 on at

    Hi

    There is no data for country and city available OOB.

  • Suggested answer
    ganeshm Profile Picture
    on at

    Entity contact = (Entity)context.InputParameters["Target"];

    ColumnSet cols = new ColumnSet(new String[] { "col1", "col2" });

    Entity entname = service.Retrieve("entityname", entity.Id, cols);

    using retrieve u can get the current instance of the record ,so retrieve it compare it

  • ah1994 Profile Picture
    195 on at

    i want to retrieve city .for example city=chennai.  i wanna update india(manually i want to update).so i wanna retrieve city and update country. both city and country is in account entity

  • joman Profile Picture
    617 on at

    Is Country entity? Is Country contains field city?

  • ah1994 Profile Picture
    195 on at

    both country and city are fields which was in account entity

  • joman Profile Picture
    617 on at

    fields: "Address1_City" and "Address1_Country"?

    It just varchar fields. If you need to fill a county, you need to make a list witch contains pair City Country to fill like you need.

    Do you have this list? Is it Dynamics entity? What name and fields in it?

    There is your QueryExpression. All you need is to place right names of entity and columns:

    QueryExpression GetCountry = new QueryExpression()
    {
    EntityName = "your_CountryCityList",
    ColumnSet = new ColumnSet("your_CountryName"),
    Criteria =
    {
    FilterOperator = LogicalOperator.And,
    Conditions =
    {
    new ConditionExpression("your_CityName", ConditionOperator.Equal, "YourCity"),
    }
    }
    }; EntityCollection Ret = service.RetrieveMultiple(GetCountry);
  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi,

    You could use the code below.

    QueryExpression query = new QueryExpression
    {
    EntityName = "account",
    ColumnSet = new ColumnSet("address1_city", "address1_country"),
    Criteria = new FilterExpression
    {
    Conditions = { new ConditionExpression { AttributeName = "address1_city", Operator = ConditionOperator.NotNull } }
    }
    };
    EntityCollection ec = service.RetrieveMultiple(query);
    if (ec.Entities.Count > 0) //Check for EntityCollection count
    {
    foreach (var item in ec.Entities)
    {
    if (item.Attributes["address1_city"].ToString() == "Chennai")
    {
    item.Attributes["address1_country"] = "India";
    service.Update(item);
    }
    }
    }

    Hope this helps.

  • Community Member Profile Picture
    on at

    Thanks! It worked for us.

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