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)

How can I populate a lookup field or dropdown field from a text field?

(0) ShareShare
ReportReport
Posted on by 2,190

Hello,

I tried to use 'on-demand workflows' to auto-populate either a drop-down list or lookup field (I created both) fron an already existing and populated text field (country field).

The problem is that when I click on my drop-down list or lookup field, I don't have any choice to look into the address1_country field.

Could anyone tell me how to?

Thanks

*This post is locked for comments

I have the same question (0)
  • Aileen Gusni Profile Picture
    44,524 on at

    Hi,

    You can auto populate from Lookup field to Text field.

    You can copy over auto populate the Country (Lookup) to Address1_Country field (Text).

    But, you cannot populate from Text field to Lookup field.

    So means that you cannot copy back from Address1_Country (Text) to Country (Lookup)

    Because the lookup field is a special field that has Guid (Entity Reference related to another entity) and Name, and also the Lookup Type (the related primary entity name).

    So, in your case, you have to create a plugin or js to retrieve the address1_country field then get the text value to find in the Master Country Data to get the Country Guid and set the lookup using the Guid. If you dont find the Guid from the text field then meaning that your Country data is not exists right now, so create a Country Data record in your Master Data

    Here is the sample code to set lookup value :

    C# in Plugin

    Entity account = new Entity("account");

    account["name"] = "Test Account1";

    EntityReference primaryContactId = new EntityReference("contact", contactId);

    account["primarycontactid"] = primaryContactId;

    You just need the Id and Entity Type

    Js

    var lookup = new Array();

    lookup[0] = new Object();

    lookup[0].id = recorid;

    lookup[0].name = recordname;

    lookup[0].entityType = entityname;

    Xrm.Page.getAttribute("attributename").setValue(lookup);

    Hope it helps!

  • sn1b Profile Picture
    2,190 on at

    Hello,

    I am unfamiliar with coding. The js script, I can insert it directly into forms (contact / lead / account) and hide the default address1_country field. When opening a contact, the script will then set the lookup value. Is that correct? But the user will then need to save each time the modification as it is done when opening a contact (in case it is already existing).

    After that, I will need to populate back the hidden address1_country field as it is required for example when creating a new contact from an already existing account.

    For writing plugins, I don't think that I will be able to manage it. The c# plugin would allow me to edit in bulk all existing contact records?

    Currently, I didn't found any solution to use a dropdown list for crm 2013 instead a text field. The issue with a text field for coutries is that users are anywhere, anytime making typo errors without carrying about it.

    Thank you!

  • Verified answer
    Aileen Gusni Profile Picture
    44,524 on at

    H, if you just one to make that from Addresses purpose since CRM city, state, and country are not lookup from Master, they are free text.

    Better, you do like that :

    1. Create entity : City, State, Country

    2. Create Lookup field from Address to City, State, and Country

    3. Only show those 3 fields in the form, hide the existing CRM fields : address1_city, address1_stateorprovince, address1_country

    4. Create a workflow to auto populate from the Lookup field (Address1_countrylookup) to the CRM Standard field (Address1_Country) after the Account created or updated, then update the Account field standard fields by the Lookup field.

    5. Let the user to type and choose the Country from the Master and save it.

    6. Workflow will be triggered and your address1_country will be populated by the selected Master, so your Address1_country is hidden but validated by the selected Master.

    I suggest different way since you cannot auti populate text field to lookup, but you can do the opposite, you can autopopulate text field by lookup label name (remember my previous post)

    "You can auto populate from Lookup field to Text field.

    You can copy over auto populate the Country (Lookup) to Address1_Country field (Text).

    But, you cannot populate from Text field to Lookup field.

    So means that you cannot copy back from Address1_Country (Text) to Country (Lookup)

    Because the lookup field is a special field that has Guid (Entity Reference related to another entity) and Name, and also the Lookup Type (the related primary entity name)."

    I think it is a better way.

    Hope it 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