标签:
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()); } }
级联视图,根据数据的上下文环境进行数据筛选的视图,我们一般在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