Dynamics CRM 2015/2016 Web API: View-based Data Query

Source: Internet
Author: User

Dynamics CRM 2015/2016 Web API: View-based Data Query

Dynamics CRM 2016 Web API supports view-based data query. The Feature that the blogger saw at the beginning has really highlighted me. This Feature is so powerful, this completely subverts the complicated and tedious method of getting data. The current view is actually defined once and reused everywhere! It is easy to use. You only need to add a parameter and specify the View ID to be called. Next, I will show you three common scenarios: calling public views, calling private views, and calling SubGrid views.

Public View

What is a public view? This is the view that everyone has access permissions. For example, the view of my available customers on the customer entity is called on the UI.

Call Code

 

            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
 
  (await getPredefinedQueryIdResp.Content.ReadAsStringAsync());                string queryId = result["value"][0]["savedqueryid"].Value
  
   ();                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
   
    (await getAccByQueryViewResp.Content.ReadAsStringAsync());                    Console.WriteLine(result2.ToString());                }            }
   
  
 


 

Private view

Private views are self-defined views for our own use. We generally call them on the UI.

Call Code

 

            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
 
  (await getUserQueryIdResp.Content.ReadAsStringAsync());                string queryId = result["value"][0]["userqueryid"].Value
  
   ();                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
   
    (await getAccByQueryViewResp.Content.ReadAsStringAsync());                    Console.WriteLine(result2.ToString());                }            }
   
  
 


 

SubGrid View

Cascading view, which is a view that filters data based on the context of the data. We usually call them on the UI.

Call Code

 

  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
 
  (await getDataBySubGridViewResp.Content.ReadAsStringAsync());                Console.WriteLine(result.ToString());            }
 


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.