
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)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/