Dynamics CRM 2015/2016 Web API: View-based data query

Source: Internet
Author: User

Dynamics CRM Web API support based on the view to query data, Bo Master at the beginning to see the feature, really let me a bright, this function too to force, completely subvert the previous complex cumbersome to take the number of ways, now the view really to define once, everywhere reuse of the point! The use of the method is also very simple, just need to add a parameter and specify the view ID that needs to be called. Next I'll show you 3 more common scenarios: calling a public view, calling a private view, calling the Subgrid view.

public view

What is a public view? is a view that everyone has access to, such as my available customers view on the customer entity, which we typically call on the UI


Calling 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.deserializeobje                Ct<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 the client.                SendAsync (Getaccbyqueryviewreq); if (getaccbyqueryviewresp.issuccessstatuscode) {Jobject result2 = Jsonconvert.deseriali                    Zeobject<jobject> (await GetAccByQueryViewResp.Content.ReadAsStringAsync ()); Console.WriteLine (RESULT2.                ToString ()); }            }


Private View

Private views are self-defined views that are designed to work for you, and we typically call them on the UI.

Calling code

            Httprequestmessage getuserqueryidreq = new Httprequestmessage (httpmethod.get, Webapiurl + "/userqueries? $filte            R=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 = Jsoncon Vert.                    Deserializeobject<jobject> (await GetAccByQueryViewResp.Content.ReadAsStringAsync ()); Console.WriteLine (RESULT2.                ToString ()); }            }


Subgrid View

Cascading views, a view of data filtering based on the context of the data, which we typically call on the UI


Calling 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< Jobject> (await GetDataBySubGridViewResp.Content.ReadAsStringAsync ());                Console.WriteLine (Result. ToString ());            }


Dynamics CRM 2015/2016 Web API: View-based data query

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.