Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Retrieving Option Set Labels with Xrm.WebApi.retrieveRecord

(0) ShareShare
ReportReport
Posted on by

Hi All,

I all prior to introduction new Client API for D365 v9, 

request.setRequestHeader("Prefer", "odata.include-annotations=OData.Community.Display.V1.FormattedValue");

was used to include Formatted Values.

How can I use Xrm.WebApi.retrieveRecord so that it returns the FormattedValues as well.

Example,

I am calling the below code

Xrm.WebApi.retrieveRequest("new_title","C859A265-6262-E811-A970-000D3A18032D","?$select=new_name,new_titletype").then(
function success(result) 
{ 
var titletype= result["new_titletype@OData.Community.Display.V1.FormattedValue"];
 // perform operations on record retrieval 
},
function (error)
{
 console.log(error.message);
 // handle error conditions
});

Here, new_titletype is an optionset attribute. Let us say for this example , it is equal to, Value:864560002 Label: "Standard"

Now, Upon Execution of above, result["new_titletype@OData.Community.Display.V1.FormattedValue"] returns undefined instead of "Standard".

Kindly assist.

Regards,

Siddharth


*This post is locked for comments

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Retrieving Option Set Labels with Xrm.WebApi.retrieveRecord

    Hi Siddharth ,

    I don't think anything wrong in your code, can you please try to debug your code to make sure result contains data .

    I would also suggest try with below code -

      function retrieveTitle() {
                try { 
                    Xrm.WebApi.retrieveRecord("new_title", "C859A265-6262-E811-A970-000D3A18032D", "?$select=new_name,new_titletype")
                        .then(function (data) {
                            retrieveTitleSuccess(data);
                        },
                         function (error) {
                             Xrm.Utility.alertDialog(error.message);
                         });
                } catch (e) {
                    Xrm.Utility.alertDialog (e.message);
                }
            }
     
            ///retrieve success
            function retrieveTitleSuccess(data) {   
                try {                
                    //optionset
                    var titletype = data["new_titletype@OData.Community.Display.V1.FormattedValue"];        
     
                } catch (e) {
                    console.log(error.message);
                }
            }

    For more information you can check below reference -

    https://www.inogic.com/blog/2018/01/dynamics-365-v9-0-xrm-webapi-crud-operations-part-1/

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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Scott_itD Profile Picture

Scott_itD 3 Community Manager

#2
Aiden Kaskela Profile Picture

Aiden Kaskela 2

#2
MikeC282 Profile Picture

MikeC282 2

Featured topics

Product updates

Dynamics 365 release plans