This article again to introduce the function of the Web API, about the text of the lookup is only slightly, because there is expand, the existing Web API can be implemented, mainly refers to the text of the option set, we find through the Basic Query API field value only with value, If you want to get text is also very simple, just need to add a message to the head of the request, the following is the C # and JS sample code.
HttpWebRequest req = (HttpWebRequest) httpwebrequest.create (Weburi); Req. Credentials = new NetworkCredential (username, pwd, domain); Req. Method = "Get"; Req. Accept = "Application/json"; Req. ContentType = "Application/json; Charset=utf-8 "; Req. Headers.set ("Odata-maxversion", "4.0"); Req. Headers.set ("Odata-version", "4.0"); Req. Headers.set ("Prefer", "Odata.include-annotations=odata.community.display.v1.formattedvalue"); using (HttpWebResponse res = (HttpWebResponse) req. GetResponse ()) { StreamReader read = new StreamReader (res. GetResponseStream ()); result = read. ReadToEnd (); }
var req = new XMLHttpRequest () req.open ("get", url); Req.setrequestheader ("Accept", "Application/json"); Req.setrequestheader ("Content-type", "Application/json; Charset=utf-8 "); Req.setrequestheader ("Odata-maxversion", "4.0"); Req.setrequestheader ("Odata-version", "4.0"); Req.setrequestheader ("Prefer", "Odata.include-annotations=odata.community.display.v1.formattedvalue"); Req.onreadystatechange = function () { if (this.readystate = = 4) { if (this.status = =) { Successcallback (J Son.parse (This.responsetext)); } else { errorcallback (Json.parse (this.responsetext). error.message);}}} ; Req.send ();
As you can see from the following, the text value has been queried.
Dynamics CRM2016 Web API Gets the text of the lookup field and the text of the option set