问题
We are facing challenge in getting formatted values of lookups available in an entity using web api.
Scenario: we have an entity with 8 lookups. When I'm querying those with Web API, getting GUIDs of those lookups, but not the names of those lookups.
回答1:
MSDN says adding header in web api request Prefer: odata.include-annotations="*"
will result you the formatted value - Name, logical name along with Id like below: (without making another call)
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
-
"_customerid_value@Microsoft.Dynamics.CRM.associatednavigationproperty":"customerid_contact",
"_customerid_value@Microsoft.Dynamics.CRM.lookuplogicalname":"contact",
"_customerid_value@OData.Community.Display.V1.FormattedValue":"Susanna Stubberod (sample)",
"_customerid_value":"7ddd0b31-ed8b-e511-80d2-00155d2a68d4",
回答2:
You can not retrieve formatted values in WebApi. you should retrieve your lookup name or any other detail(field) by a second call and retrieve name or any field of lookup using its GUID
来源:https://stackoverflow.com/questions/47237971/how-to-retrieve-formatted-values-of-lookups-in-an-entity