码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2016-05-18 18:35:24      阅读:364      评论:0      收藏:0      [点我收藏+]

标签:

      本篇再来介绍个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

标签:

原文地址:http://blog.csdn.net/vic0228/article/details/51427615

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!