3

I have an entity called as medical record

I am fetching the list of families in the medical record entity(subgrid)

I am able to fetch the list of families using api call

 http://localhost/CRMDataBase/api/data/v8.0/new_medcase(1a7f5ac3-b116-e611-9425-000d3a12d0d4)?$expand=new_case_family

But the problem is, I want to get the text from drop down field instead of the value in the family. i.e I have a field called new_typeoffamily and it has values like "nuclear", "joint" etc But the api call is fetching values like 100000,1000001

How can I get the text selected using the api call?

Vignesh Subramanian
  • 7,161
  • 14
  • 87
  • 150

2 Answers2

4

I believe you will need to set the query to also return formatted values.

Request:

GET [Organization URI]/api/data/v8.1/accounts?$select=name,donotpostalmail,accountratingcode,numberofemployees,revenue&$top=1 HTTP/1.1
Accept: application/json
OData-MaxVersion: 4.0
OData-Version: 4.0
Prefer: odata.include-annotations="OData.Community.Display.V1.FormattedValue"

Result:

HTTP/1.1 200 OK
Content-Type: application/json; odata.metadata=minimal
OData-Version: 4.0
Preference-Applied: odata.include-annotations="OData.Community.Display.V1.FormattedValue"

{
 "@odata.context": "[Organization URI]/api/data/v8.1/$metadata#accounts(name,donotpostalmail,accountratingcode,numberofemployees,revenue)",
 "value": [
 {
  "@odata.etag": "W/"502170"",
  "name": "Fourth Coffee (sample)",
  "donotpostalmail@OData.Community.Display.V1.FormattedValue": "Allow",
  "donotpostalmail": false,
  "accountratingcode@OData.Community.Display.V1.FormattedValue": "Default Value",
  "accountratingcode": 1,
  "numberofemployees@OData.Community.Display.V1.FormattedValue": "9,500",
  "numberofemployees": 9500,
  "revenue@OData.Community.Display.V1.FormattedValue": "$100,000.00",
  "revenue": 100000,
  "accountid": "89390c24-9c72-e511-80d4-00155d2a68d1",
  "transactioncurrencyid_value": "50b6dd7b-f16d-e511-80d0-00155db07cb1" } ]
}

Source: Include formatted values

James Wood
  • 17,286
  • 4
  • 46
  • 89
  • Thanks James, I am using ajax calls, should it be like this `$.ajax({ url:"serverurl/organizationdata.svc/new_entityName", headers: { "Accept": "application/json; odata=verbose" ,"Prefer":"odata.include-annotations="OData.Community.Display.V1.FormattedValue"},` – Vignesh Subramanian May 12 '16 at 10:33
  • 1
    I don't know, I just copied that example from the MSDN :) – James Wood May 12 '16 at 10:41
  • 1
    okay, will accept yours and add my answer for people who want ajax configuration :) thanks – Vignesh Subramanian May 12 '16 at 11:01
3

Add the following headers before making the request

parent.$.ajax({
url : customurl,
headers: {
"Accept": "application/json" ,
"Content-Type":"application/json; charset=utf-8",
"OData-MaxVersion":"4.0",
"OData-Version":"4.0",
"Prefer":"odata.include-annotations=OData.Community.Display.V1.FormattedValue"
},

Now the data will have values like before

new_modeofcontact: 1000001
new_modeofcontact@OData.Community.Display.V1.FormattedValue    :    "Email"
Vignesh Subramanian
  • 7,161
  • 14
  • 87
  • 150