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)

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

I have the same question (0)
  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    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

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