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 365 | Integration, Dataverse...
Answered

Mapping 1 PCF Control Choice Field to a Choice Field

(1) ShareShare
ReportReport
Posted on by 183
Hello, 
 
I am using the PCF Control Country Picker: Country Picker | PCF Gallery This allows me to choose a country from a field named 'cra1c_countriespcf' on which this pcf control is applied.
 
The thing is, I already have a Choice field called new_ti_countries, synced with global choice option-set 'new_ti_country' which contains Country names as labels and their values.
 
Since the Country field that is synced with the global option-set was the field previously adopted and used where multiple events are connected to it and it is related to around 5 other fields, and since it is different from the Country field on which the PCF control is applied, I am trying to set the choice selected in the newly created PCF Control Country Field as the choice selected in the old Country field. (See Image Below)
 
//////
 
I am trying to get the value of the selected choice in the PCF Control field (France in the example above), find the Value of Label France in the global option-set, and set that fetched value as the selected choice of the old 'Country' field. My problem is that the line '
var selectedCountryValue = Xrm.Page.getAttribute(/cra1c_countriespcf/).getValue();
' is returning FRA instead of France. FRA does not exist as a label in my option-set. This is the case with any other selected choice: instead of getting New Zealand, I get NZL, AUS instead of Australia, etc...
 
// JavaScript function to find and set the corresponding value in the new_ti_countries fieldfunction setNewTiCountriesValue() {    // Get the selected country value from cra1c_countriespcf field    var selectedCountryValue = Xrm.Page.getAttribute(/cra1c_countriespcf/).getValue();    // Check if the selected country value is not null    if (selectedCountryValue !== null) {        // Log the selected country value for debugging        console.log(/Selected Country Value:/, selectedCountryValue);        // Fetch the global choice option-set new_ti_countries        var globalOptionSet = Xrm.Page.getAttribute(/new_ti_countries/).getOptions();        // Log all available values in new_ti_countries for debugging        console.log(/Available Values in new_ti_countries:/);        for (var i = 0; i < globalOptionSet.length; i++) {            console.log(globalOptionSet[i].value, globalOptionSet[i].text);            if (globalOptionSet[i].value === selectedCountryValue) {                // Set the corresponding value to the new_ti_countries field                Xrm.Page.getAttribute(/new_ti_countries/).setValue(selectedCountryValue);                return;            }        }        console.error(/Corresponding value not found for the selected country./);    }}
 
I would highly appreciate any hints on how to get the common name of the country instead of its code. I think it has to do with the control, but I can't seem to fetch it. Thank you in advance for any help!
I have the same question (0)
  • Suggested answer
    Leah Ju Profile Picture
    Microsoft Employee on at
    Choice field?
    I notice that you use 'getValue()' fucntion in your code.
    Maybe you can try to use 'getText()' function, which returns a string value of the text for the currently selected option for a choice or choices column.

    I hope you can mark my answer verified if it is helpful! If you have any questions, please feel free to contact me.
    Regards,
    Leah
     
  • Verified answer
    Joseph Nasr Profile Picture
    183 on at
    Hello Leah,
     
    I managed to make it work. getText() did not work, but I created a hardcoded list of country codenames mapped to an array of the Country name and Country Index based on how they are in the global choice like below:
     
    var countryCodeNames = {
    'FRA' : ["France", 24],
    'AUS': ["Australia, 26],
    ...
    }
     
    Then I use getValue() to get the codename of the selected result, and using the object above, I set its country index as the value of my other field. I know it's hardcoded, but it works and I don't think anyone will be changing country names soon :P
     
  • Leah Ju Profile Picture
    Microsoft Employee on at
    Hi Partner,
    Agreed!
    Your method is presumably the most effective one.
    We can't change the country name inside the PCF control, we can only figure it out on our own customisable country field.
     

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 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 58 Most Valuable Professional

#2
#ManoVerse Profile Picture

#ManoVerse 42

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 38 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans