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

Dynamics CRM 2015/2016 Web API:基于视图的数据查询

时间:2016-02-14 17:03:27      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:

Dynamics CRM 2016 Web API支持基于视图来查询数据,博主初看到该Feature,着实让我眼前一亮,这个功能太给力了,完全颠覆了之前复杂繁琐的取数方式了,现在的视图真正到了定义一次,处处复用的地步了!使用方法也很简单,只需要加个参数并指定需要调用的View ID就好了。接下来我给大家演示3个比较常用的场景:调用公共视图,调用私有视图,调用SubGrid视图。

公共视图

什么是公共视图?就是大家都有权限访问的视图,比如客户实体上的我的可用客户视图,我们一般在UI上面这么调用它们

技术分享

调用代码

            HttpRequestMessage getPredefinedQueryIdReq = new HttpRequestMessage(HttpMethod.Get, webApiUrl + "/savedqueries?$filter=name eq ‘My Active Accounts‘");
            getPredefinedQueryIdReq.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessCode);

            HttpResponseMessage getPredefinedQueryIdResp = await client.SendAsync(getPredefinedQueryIdReq);
            if (getPredefinedQueryIdResp.IsSuccessStatusCode)
            {
                JObject result = JsonConvert.DeserializeObject<JObject>(await getPredefinedQueryIdResp.Content.ReadAsStringAsync());
                string queryId = result["value"][0]["savedqueryid"].Value<string>();

                HttpRequestMessage getAccByQueryViewReq = new HttpRequestMessage(HttpMethod.Get, webApiUrl + "/accounts?savedQuery=" + queryId);
                getAccByQueryViewReq.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessCode);

                HttpResponseMessage getAccByQueryViewResp = await client.SendAsync(getAccByQueryViewReq);
                if (getAccByQueryViewResp.IsSuccessStatusCode)
                {
                    JObject result2 = JsonConvert.DeserializeObject<JObject>(await getAccByQueryViewResp.Content.ReadAsStringAsync());
                    Console.WriteLine(result2.ToString());

                }
            }


私有视图

私有视图就是自己定义的视图,专为自己使用,我们一般在UI上面这么调用它们

技术分享

调用代码

            HttpRequestMessage getUserQueryIdReq = new HttpRequestMessage(HttpMethod.Get, webApiUrl + "/userqueries?$filter=name eq ‘Jeffs View‘");
            getUserQueryIdReq.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessCode);

            HttpResponseMessage getUserQueryIdResp = await client.SendAsync(getUserQueryIdReq);
            if (getUserQueryIdResp.IsSuccessStatusCode)
            {
                JObject result = JsonConvert.DeserializeObject<JObject>(await getUserQueryIdResp.Content.ReadAsStringAsync());
                string queryId = result["value"][0]["userqueryid"].Value<string>();

                HttpRequestMessage getAccByQueryViewReq = new HttpRequestMessage(HttpMethod.Get, webApiUrl + "/accounts?userQuery=" + queryId);
                getAccByQueryViewReq.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessCode);

                HttpResponseMessage getAccByQueryViewResp = await client.SendAsync(getAccByQueryViewReq);
                if (getAccByQueryViewResp.IsSuccessStatusCode)
                {
                    JObject result2 = JsonConvert.DeserializeObject<JObject>(await getAccByQueryViewResp.Content.ReadAsStringAsync());
                    Console.WriteLine(result2.ToString());

                }
            }


SubGrid视图

级联视图,根据数据的上下文环境进行数据筛选的视图,我们一般在UI上面这么调用它们

技术分享

调用代码

  HttpRequestMessage getDataBySubGridViewReq = new HttpRequestMessage(HttpMethod.Get, webApiUrl + "/accounts(823ef58a-75bb-e511-80d9-c4346bc43f3c)/contact_customer_accounts/?savedQuery=00000000-0000-0000-00aa-000010001033");
            getDataBySubGridViewReq.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessCode);

            HttpResponseMessage getDataBySubGridViewResp = await client.SendAsync(getDataBySubGridViewReq);
            if (getDataBySubGridViewResp.IsSuccessStatusCode)
            {
                JObject result = JsonConvert.DeserializeObject<JObject>(await getDataBySubGridViewResp.Content.ReadAsStringAsync());
                Console.WriteLine(result.ToString());
            }


Dynamics CRM 2015/2016 Web API:基于视图的数据查询

标签:

原文地址:http://blog.csdn.net/ghostbear/article/details/50610938

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