Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Dropdown with custom value => label pairs

Posted on by 5

I'm relatively new to Dynamics and have come across a problem that seems very simple, but I can't seem to get it to work.

I want to create a custom field, a dropdown, that has independent value and label pairs.

It's niche, but think of something like

USD => US Dollar

GBP => British Pound Sterling

EUR => Euro

The value is important bit for interacting with an external system, but for user experience, the label gives a useful select mechanism.

My goto was an 'Option Set', but I seem unable to edit the values - they're forced numbers of 10,000,000 or similar.

I can't believe that this isn't possible, but have spent hours trying to get around it - what am I doing wrong and how do I achieve this (simple) goal?

Any help appreciated!

  • MarkCA Profile Picture
    MarkCA 5 on at
    RE: Dropdown with custom value => label pairs

    Fantastic response @Clofly, thank you.

    I need to digest some of this and look to getting it implemented, that may take a little time.

    I'm slowly getting to grips with the monster that is Dynamics - but it is certainly not a straightforward undertaking!

    Thanks again for taking the time to help me out.

  • Verified answer
    cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: Dropdown with custom value => label pairs

    Hi MarkCA,

    If you are using Flow, then you could take method below as reference for how to get optionset label text and set an option of optionset by text.

    - Get optionset label text

    In Flow, the limitation is that only the optionset value can be chosen from the dynamic content.

    However, the label is actually existing in returned JSON body, we could fetch it manually by expression in such format: 

    items('Apply_to_each')?['_optionsetname_label']

    e.g: Get prefered contact method of a specific contact person:

    7610.JPG

    Result:

    pastedimage1591064004241v1.png

    - Set an option of optionset by text 

    In Dynamics 365, there is an entity called "String Map" to record all optionset mapping relationship of all entities, it has 4 key fields:

    > objecttypecode: source entity name, such as account or contact

    > attributename: optionset field name

    > attributevalue: option value

    > value: option label

    We can retrieve any optionset mapping records by web api, an example:

    api/data/v9.1/stringmaps?$filter=objecttypecode eq 'contact'and attributename eq 'preferredcontactmethodcode'

    It will return all mapping relationship records of Preferred Method of Contact field of Contact entity.(By default the total result lenght is 5.)

    pastedimage1591064997611v2.png

    So if the corresponding item of Dynamics option in your external system is label, then you could query stringmap entity to get corresponding integer value and set the optionset field by the value. 

    You could also take blog article below as reference: 

    http://crmaddicted.blogspot.com/2020/01/working-with-optionset-lables-in-power.html?m=1

    Regards,

    Clofly

  • MarkCA Profile Picture
    MarkCA 5 on at
    RE: Dropdown with custom value => label pairs

    The requirement is for communicating with an external system via a SOAP service.

    It just seems impossible, but I can't believe it's that wild of a requirement.

    I'm trying to tackle each issue as it comes, but in essence, I want to pull the list from the external system and add a dropdown with value => label pairs that can then be used to update the external system.

    But:

    • I can't build a custom connector because SOAP uses XML not JSON, so I'm using Flow with manual calls
    • I can't create an Option Set from the resultant list request
    • I can't create an option set using value => label pairs

    The result means that it looks like I need to create the option labels manually and map them using JS or Flow, whilst remembering to update if there are any changes in future.

    I just can't fathom that this is the best way to achieve this and conclude that I am missing something fundamental... but I just don't know what it is and could really benefit from some guidance.

  • cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: Dropdown with custom value => label pairs

    Hi MarkCA,

    The value of a option could be only integer number, which is by design.

    Could you share me reason or business requirement that why do you want to set value of option to string?

    We can get option text directly by javascript: formContext.getAttribute("new_field").getSelectedOption().text;

    You could do mapping manually if you would like to populate a text field once selecting an option.

    var text = formContext.getAttribute('new_field').getSelectedOption().text;
    if (text === 'US Dollar') {
      formContext.getAttribute('new_field2').setValue('USD')
    }
    

    Regards,

    Clofly

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Dropdown with custom value => label pairs

    Hello,

    I'm afraid you would not be able to achieve your exact requirement easily.

    The simplest way I see is to create a custom entity (or use standard Currency) and add a reference/lookup to your entity with that new one.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans