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

Retrieve values from Choices using JS

(6) ShareShare
ReportReport
Posted on by 48
Hello!

Is it possible to retrieve Choices values (numeric and label) using Javascript?

For example, we want to retrieve values of Purchase Process choice.

Categories:
I have the same question (0)
  • Verified answer
    Jimmy Passeti Profile Picture
    674 Most Valuable Professional on at
    Hello,
     
    YEs, it´s possible!
     
    You can use below code to retrieve the internal value:
    formContext.getAttribute("address1_addresstypecode").getSelectedOption().value;
     
    And below code to retrieve the optionset label:
    formContext.getAttribute("address1_addresstypecode").getSelectedOption().text;
     
     
    Regards,
    Jimmy Passeti | Microsoft MVP
    ✅ Please mark as Verified if this answered your question!
     
  • Verified answer
    Aymen CHELBI Profile Picture
    576 on at
    Hello,

    Yes! You can retrieve the values (both numeric and label) of a Choice (Option Set) field in Dynamics 365 using JavaScript.

    Retrieving Choice Values using JavaScript

    1. To get the selected value (numeric and label) from a form:
    var purchaseProcessField = Xrm.Page.getAttribute("purchaseprocess");
    if (purchaseProcessField) {
    var selectedValue = purchaseProcessField.getValue();
    var selectedLabel = purchaseProcessField.getText();
    console.log("Value:", selectedValue, "Label:", selectedLabel);
    }
    1. To get all available options for the Choice field:
    var options = Xrm.Page.getAttribute("purchaseprocess").getOptions();
    options.forEach(function(option) {
    console.log("Value:", option.value, "Label:", option.text);
    });

    For Power Apps Unified Interface (Client API)

    If you're using the newer formContext model:

    var formContext = executionContext.getFormContext();
    var options = formContext.getAttribute("purchaseprocess").getOptions();
    options.forEach(function(option) {
    console.log("Value:", option.value, "Label:", option.text);
    });

    Best regards,

  • Jean M. Profile Picture
    48 on at
    Hello Jimmy Passeti | MVP and Aymen CHELBI, 

    Thank you for your assistance in providing the code. 

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
iampranjal Profile Picture

iampranjal 51

#2
Martin Dráb Profile Picture

Martin Dráb 39 Most Valuable Professional

#3
André Arnaud de Calavon Profile Picture

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

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans