We often have to do data query on the client, the following are more commonly used in several query methods: XMLHttpRequest, SDK. JQuery, SDK. Rest.
XMLHttpRequest is the most basic way to call, and the two ways of jquery and rest are actually used XMLHttpRequest, just to encapsulate it.
jquery and rest two ways to interface, so the same way
1. XMLHttpRequest
function Odataretrieve (odatastring) {
2: var serverurl = Xrm.Page.context.getClientUrl ();
3: if (Serverurl.match (/\/$/)) {
4: ServerURL = serverurl.substring (0, ServerURL. Length -1);
5: }
6: varnew XMLHttpRequest ();
7: retrievereq. Open("GET", ServerURL + "/xrmservices/2011/organizationdata.svc/false");
8: retrievereq.setrequestheader ("Accept", "Application/json");
9: retrievereq.setrequestheader ("content-type", "application/json;charset=utf-8");
Ten: retrievereq.send ();
One: return json.parse (retrievereq.responsetext). D;
12:}
1:var retrievedcontact = Odataretrieve ("contactset (GUID ') + contactattribute.getvalue () [0].id +"')? Select=jobtitle,mobilephone");
2: if (retrievedcontact! = null) {
3: contactjobattribute.setvalue (Retrievedcontact.jobtitle);
4: contactphoneattribute.setvalue (Retrievedcontact.mobilephone);
5:}
2. SDK. Jquery
- Sdk. Jquery.js located under Sdk\samplecode\js\restendpoint\jqueryrestdataoperations\jqueryrestdataoperations\scripts
function Select, expand, Successcallback, Errorcallback)
function (Type, options, Successcallback, Errorcallback, OnComplete)
1:sdk. Jquery.retrieverecord (
2: AccountId,
3: "account",
4: null, NULL,
5: function (account) {
6: writemessage ("retrievedthe account named") + account. Name + "\". This account is created on: \ "" + account. CreatedOn + "\".");
7: Updateaccount (ACCOUNTID);
8: },
9: ErrorHandler
: );
1:sdk. Jquery.retrievemultiplerecords (
2: "Contact",
3: "$select =contactid,fullname& $top =1",
4: function (results) {
5: var firstresult = results[0];
6: if (firstresult! = null) {
7: primarycontact = results[0];
8: }
9: Else {
Ten: writemessage ("No Contact records is available to setas the" the primary with the account. ");
One: }
: },
: ErrorHandler,
: function () {
: //oncomplete Handler
: }
: );
3. SDK. Rest
- Sdk. Rest.js is located in sdk\samplecode\js\restendpoint\javascriptrestassociatedisassociate\ Javascriptrestassociatedisassociate\scripts under
function Select, expand, Successcallback, Errorcallback)
function (Type, options, Successcallback, Errorcallback, OnComplete)
1: SDK. Rest.retrieverecord (
2: AccountId,
3: "account",
4: Null,null,
5: function (account) {
6: writemessage ("retrievedthe account named") + account. Name + "\". This account is created on: \ "" + account. CreatedOn + "\".");
7: Updateaccount (ACCOUNTID);
8: },
9: ErrorHandler
: );
1:sdk. Rest.retrievemultiplerecords (
2: "Contact",
3: "$select =contactid,fullname& $top =1",
4: function (results) {
5: var firstresult = results[0];
6: if (firstresult! = null) {
7: primarycontact = results[0];
8: }
9: Else {
Ten: writemessage ("No Contact records is available to setas the" the primary with the account. ");
One: }
: },
: ErrorHandler,
: function
: //oncomplete Handler
: }
: );
Dynamic CRM 2013 Learning Notes Series Rollup
Dynamic CRM 2013 Learning Notes (10) client comparison of several query data modes