Dynamics CRM2016 Web API之获取查找字段的text及选项集的text

Posted Vic.Tang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Dynamics CRM2016 Web API之获取查找字段的text及选项集的text相关的知识,希望对你有一定的参考价值。

      本篇再来介绍个web api的功能,关于lookup的text这里只是略带,因为有expand,现有的web api就能实现,主要提的是选项集的text,我们通过基本的查询api查出来的字段值只带有value,如果想要获取text也很简单,只需要在request的头部加一条信息即可,下面分别给出了C#及JS的示例代码。

 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 == 200) {
                successCallback(JSON.parse(this.responseText));
            }
            else {
                errorCallback(JSON.parse(this.responseText).error.message);
            }
        }
    };
    req.send();

      从下面的截图就能看到,text值已查询出。


以上是关于Dynamics CRM2016 Web API之获取查找字段的text及选项集的text的主要内容,如果未能解决你的问题,请参考以下文章

Dynamics CRM2016 Web API之删除

Dynamics CRM 2015/2016 Web API:注册 APP(调用CRM Online Web API)

Dynamics CRM2016 Web API之更新记录

Dynamics CRM2016 Web Api之更新时间字段值

Dynamics CRM2016 Web API之Use custom FetchXML

Dynamics CRM 2015/2016 Web API:聚合查询