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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Get Country from Lookup list

(0) ShareShare
ReportReport
Posted on by 275

Hello, I have added a lookup list with all countries, now I would like to link the existing field Adress1 country/region to this lookup list. Could anyone help me please. I am new to CRM. Thanks

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Aileen Gusni Profile Picture
    44,524 on at
    RE: Get Country from Lookup list

    Hi Elisabeth123,

    There are many ways you can do:

    1. Create a workflow to copy the lookup value to the Address1 Country field

    2. Using javascript

    You can use javascript to get the lookup id and you need to copy the value of the name to the address1 country/region field:

    var lookupObject = Xrm.Page.getAttribute("yourcountryfieldname");

        if (lookupObject != null)
      {

            var lookUpObjectValue = lookupObject.getValue();

            if ((lookUpObjectValue != null))

            {

             var lookuptextvalue = lookUpObjectValue[0].name;
             var lookupid = lookUpObjectValue[0].id;

             //set to address1 field

          Xrm.Page.data.entity.attributes.get("address1_country").setValue(lookuptextvalue);

            }

      }
    3. You can use plugin
    To avoid custom code, you can use workflow to copy over the field lookup value to the address1: Country.
    Create a new workflow on entity Account/Contact based your requirement, add trigger when onCreate and when Country lookup field was changed.
    Add step: Update the Account/Contact record, set the address1:Country field to the lookup value.
    Hope this helps!
    THanks.
  • Suggested answer
    Hosk Profile Picture
    on at
    RE: Get Country from Lookup list

    If you are not a coder then the easiest way would be to use 

    Business rules

    or

    Real Time workflow

    This article shows you how to copy all the addresses field using business rules but you should be able to modify it

    http://niiranen.eu/crm/2013/12/address-copy-button-business-rules-workflows/

  • Community Member Profile Picture
    on at
    RE: Get Country from Lookup list

    To clarify: Aileen's code is great if you have added a lookup field for country - a lookup links to another record, so this would be useful if you have created a custom entity for Country (quite a common approach). If you have in fact added an "option set" (aka "picklist") then you would need to use similar but slightly simpler javascript code.

    Let us know how you have done your customisation to add a list of Countries so we can better advise.

    You might also need to change this for CRM 2013 if the original country field only appear within the Address1_composite control on the form. See this post for information:

    https://community.dynamics.com/crm/b/crminogic/archive/2014/10/21/accessing-composite-controls-programmatically-using-script.aspx

  • Waqar Sohail Profile Picture
    on at
    RE: Get Country from Lookup list

    Hi Alisabeth, Easy way to do this is workflow if you don't want to show the values on the Change of Country Lookup. You can set country lookup to Address1  on Create or Update of record.

    But if you want to set the values on change of country then You need to write simple Javascript

  • elisabeth123 Profile Picture
    275 on at
    RE: Get Country from Lookup list

    Thanks for the replies, what I have done is:

    1) created a new entity and imported the data, which is a list with countries, code and continent,

    2) in the account I added a relationship and a new search field. This is working so fine so far.

    3) When trying to create a business rule, it seems that I only can copy fields with the same datatype,

    what I tried is: when country does not contain data -> set field value address 1: country region - value - countryList (here I can't pick my list)

    With javascript I am not quite clear where to put it

    It would also be possible to use an option set, if this is easier to handle.

  • elisabeth123 Profile Picture
    275 on at
    RE: Get Country from Lookup list

    Hello, is it possible to copy a the selected value from the search field to the country field, whenever I try to make a business rule, I only get fields of the same type select.

    Thanks.

  • Verified answer
    Aileen Gusni Profile Picture
    44,524 on at
    RE: Get Country from Lookup list

    Hi Elisabeth,

    If that, then Not by Business Rules.

    If you want to copy from Lookup to Text, then you can do it by workflow.

    You can update the value of the text field from the Lookup field.

    Thanks.

  • elisabeth123 Profile Picture
    275 on at
    RE: Get Country from Lookup list

    Thank you, this was exactly what I wanted.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans